-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathIDbConnectionExtensions.cs
144 lines (131 loc) · 5.97 KB
/
IDbConnectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using InterpolatedSql.SqlBuilders;
using System;
using System.Data;
using SqlBuilder = InterpolatedSql.Dapper.SqlBuilders.SqlBuilder;
using QueryBuilder = InterpolatedSql.Dapper.SqlBuilders.QueryBuilder;
using InterpolatedSql.Dapper.SqlBuilders;
namespace InterpolatedSql.Dapper
{
/// <summary>
/// Extends IDbConnection to easily build QueryBuilder or SqlBuilder
/// </summary>
public static partial class IDbConnectionExtensions
{
public static SqlBuilderFactory SqlBuilderFactory { get; set; } = SqlBuilderFactory.Default;
#region SqlBuilder
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B over current connection
/// </summary>
public static B SqlBuilder<B>(this IDbConnection cnn)
where B : IDapperSqlBuilder
{
return SqlBuilderFactory.Create<B>(cnn);
}
#if NET6_0_OR_GREATER
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static B SqlBuilder<B>(this IDbConnection cnn, ref InterpolatedSqlHandler command)
where B : IDapperSqlBuilder
{
if (command.InterpolatedSqlBuilder.Options.AutoAdjustMultilineString)
command.AdjustMultilineString();
return SqlBuilderFactory.Create<B>(cnn, command.InterpolatedSqlBuilder.AsFormattableString());
}
/// <summary>
/// Creates a new SqlBuilder over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static SqlBuilder SqlBuilder(this IDbConnection cnn, ref InterpolatedSqlHandler command)
{
if (command.InterpolatedSqlBuilder.Options.AutoAdjustMultilineString)
command.AdjustMultilineString();
return new SqlBuilder(cnn, command.InterpolatedSqlBuilder.AsFormattableString());
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static B SqlBuilder<B>(this IDbConnection cnn, InterpolatedSqlBuilderOptions options, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgument("options")] ref InterpolatedSqlHandler command)
where B : IDapperSqlBuilder
{
if (command.InterpolatedSqlBuilder.Options.AutoAdjustMultilineString)
command.AdjustMultilineString();
return SqlBuilderFactory.Create<B>(cnn, command.InterpolatedSqlBuilder.AsFormattableString());
}
/// <summary>
/// Creates a new SqlBuilder over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static SqlBuilder SqlBuilder(this IDbConnection cnn, InterpolatedSqlBuilderOptions options, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgument("options")] ref InterpolatedSqlHandler command)
{
if (command.InterpolatedSqlBuilder.Options.AutoAdjustMultilineString)
command.AdjustMultilineString();
return new SqlBuilder(cnn, command.InterpolatedSqlBuilder.AsFormattableString());
}
#else
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static B SqlBuilder<B>(this IDbConnection cnn, FormattableString command)
where B : IDapperSqlBuilder
{
return SqlBuilderFactory.Create<B>(cnn, command);
}
/// <summary>
/// Creates a new SqlBuilder over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static SqlBuilder SqlBuilder(this IDbConnection cnn, FormattableString command)
{
return new SqlBuilder(cnn, command);
}
/// <summary>
/// Creates a new IInterpolatedSqlBuilder of type B over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static B SqlBuilder<B>(this IDbConnection cnn, InterpolatedSqlBuilderOptions options, FormattableString command)
where B : IDapperSqlBuilder
{
return SqlBuilderFactory.Create<B>(cnn, command, options);
}
/// <summary>
/// Creates a new SqlBuilder over current connection
/// </summary>
/// <param name="command">SQL command</param>
public static SqlBuilder SqlBuilder(this IDbConnection cnn, InterpolatedSqlBuilderOptions options, FormattableString command)
{
return new SqlBuilder(cnn, command, options);
}
#endif
/// <summary>
/// Creates a new empty SqlBuilder over current connection
/// </summary>
public static SqlBuilder SqlBuilder(this IDbConnection cnn, InterpolatedSqlBuilderOptions? options = null)
{
return new SqlBuilder(cnn, options);
}
#endregion
#region QueryBuilder
/// <summary>
/// Creates a new QueryBuilder over current connection
/// </summary>
/// <param name="query">You can use "{where}" or "/**where**/" in your query, and it will be replaced by "WHERE + filters" (if any filter is defined). <br />
/// You can use "{filters}" or "/**filters**/" in your query, and it will be replaced by "filters" (without where) (if any filter is defined).
/// </param>
public static QueryBuilder QueryBuilder(this IDbConnection cnn, FormattableString query)
{
return new QueryBuilder(cnn, query);
}
/// <summary>
/// Creates a new empty QueryBuilder over current connection
/// </summary>
public static QueryBuilder QueryBuilder(this IDbConnection cnn)
{
return new QueryBuilder(cnn);
}
#endregion
}
}