-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathQueryBatch.cs
60 lines (50 loc) · 1.86 KB
/
QueryBatch.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
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace SecurityDriven.TinyORM
{
using Utils;
using NameValueTypeTuple = ValueTuple<string, Dictionary<string, (object, Type)>>;
public sealed class QueryBatch
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static QueryBatch Create() => new QueryBatch();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static QueryBatch Create(IEnumerable<QueryBatch> queryBatchList) => new QueryBatch().Append(queryBatchList);
internal QueryBatch() { }
internal List<NameValueTypeTuple> queryList = new List<NameValueTypeTuple>();
public QueryBatch AddQuery<TParamType>(string sql, TParamType param) where TParamType : class
{
Dictionary<string, (object, Type)> paramDictionary;
if (param == null)
paramDictionary = new Dictionary<string, (object, Type)>(0, StringComparer.Ordinal);
else if (param is Dictionary<string, (object, Type)> _paramDictionary)
paramDictionary = _paramDictionary;
else
paramDictionary = ReflectionHelper_Shared.ObjectToDictionary_Parameterized<TParamType>(param);
var query = new NameValueTypeTuple(sql, paramDictionary);
queryList.Add(query);
return this;
}// AddQuery<TParamType>()
public QueryBatch AddQuery(string sql)
{
this.AddQuery<string>(sql: sql, param: null);
return this;
}// AddQuery() - parameterless
public QueryBatch AddQuery(QueryInfo queryInfo)
{
this.AddQuery(sql: queryInfo.SQL, param: queryInfo.ParameterMap);
return this;
}// AddQuery() - QueryInfo
public QueryBatch Append(QueryBatch queryBatch)
{
this.queryList.AddRange(queryBatch.queryList);
return this;
}// Append()
public QueryBatch Append(IEnumerable<QueryBatch> queryBatchList)
{
foreach (var list in queryBatchList) this.Append(list);
return this;
}// Append()
}//class QueryBatch
}//ns