-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBatchQuery.cs
More file actions
53 lines (45 loc) · 1.43 KB
/
BatchQuery.cs
File metadata and controls
53 lines (45 loc) · 1.43 KB
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
using System.Collections.Generic;
using System.Linq;
namespace Queries.Core.Builders;
/// <summary>
/// Represents many <see cref="IQuery"/>s that will be executed as a whole
/// </summary>
public class BatchQuery : IQuery
{
private readonly List<IQuery> _statements;
/// <summary>
/// Statements that the current instance holds.
/// </summary>
public IReadOnlyList<IQuery> Statements
#if NETSTANDARD
=> _statements.ToArray();
#else
=> _statements.AsReadOnly();
#endif
/// <summary>
/// Builds a new <see cref="BatchQuery"/> instance.
/// </summary>
/// <param name="queries">queries of the batch.</param>
public BatchQuery(params IQuery[] queries) => _statements = queries.Where(x => x is not null)
.ToList();
/// <summary>
/// Adds a statement to this instance
/// </summary>
/// <param name="query">The query to add</param>
/// <returns></returns>
public BatchQuery AddStatement(IQuery query)
{
_statements.Add(query);
return this;
}
/// <summary>
/// Adds multiple statements to the current instance
/// </summary>
/// <param name="queries"></param>
/// <returns>The current instance</returns>
public BatchQuery AddStatements(IEnumerable<IQuery> queries)
{
_statements.AddRange(queries.Where(q => q is not null));
return this;
}
}