• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 23278216331

19 Mar 2026 03:19AM UTC coverage: 57.398% (+0.7%) from 56.658%
23278216331

push

github

pwelter34
Enable nullable and improve source generators

1403 of 3069 branches covered (45.72%)

Branch coverage included in aggregate %.

527 of 907 new or added lines in 58 files covered. (58.1%)

22 existing lines in 10 files now uncovered.

4288 of 6846 relevant lines covered (62.64%)

330.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.3
/src/FluentCommand/Query/DeleteBuilder.cs
1
using FluentCommand.Extensions;
2
using FluentCommand.Query.Generators;
3

4
namespace FluentCommand.Query;
5

6
/// <summary>
7
/// Provides a builder for constructing SQL DELETE statements with fluent, chainable methods.
8
/// </summary>
9
public class DeleteBuilder : DeleteBuilder<DeleteBuilder>
10
{
11
    /// <summary>
12
    /// Initializes a new instance of the <see cref="DeleteBuilder"/> class.
13
    /// </summary>
14
    /// <param name="queryGenerator">The <see cref="IQueryGenerator"/> used to generate SQL expressions.</param>
15
    /// <param name="parameters">The list of <see cref="QueryParameter"/> objects for the query.</param>
16
    /// <param name="logicalOperator">The logical operator (<see cref="LogicalOperators"/>) to combine WHERE expressions. Defaults to <see cref="LogicalOperators.And"/>.</param>
17
    public DeleteBuilder(
18
        IQueryGenerator queryGenerator,
19
        List<QueryParameter> parameters,
20
        LogicalOperators logicalOperator = LogicalOperators.And)
21
        : base(queryGenerator, parameters, logicalOperator)
×
22
    {
23
    }
×
24
}
25

26
/// <summary>
27
/// Provides a generic base class for building SQL DELETE statements with fluent, chainable methods.
28
/// </summary>
29
/// <typeparam name="TBuilder">The type of the builder for fluent chaining.</typeparam>
30
public abstract class DeleteBuilder<TBuilder> : WhereBuilder<TBuilder>
31
    where TBuilder : DeleteBuilder<TBuilder>
32
{
33
    /// <summary>
34
    /// Initializes a new instance of the <see cref="DeleteBuilder{TBuilder}"/> class.
35
    /// </summary>
36
    /// <param name="queryGenerator">The <see cref="IQueryGenerator"/> used to generate SQL expressions.</param>
37
    /// <param name="parameters">The list of <see cref="QueryParameter"/> objects for the query.</param>
38
    /// <param name="logicalOperator">The logical operator (<see cref="LogicalOperators"/>) to combine WHERE expressions. Defaults to <see cref="LogicalOperators.And"/>.</param>
39
    protected DeleteBuilder(
40
        IQueryGenerator queryGenerator,
41
        List<QueryParameter> parameters,
42
        LogicalOperators logicalOperator = LogicalOperators.And)
43
        : base(queryGenerator, parameters, logicalOperator)
6✔
44
    {
45
    }
6✔
46

47
    /// <summary>
48
    /// Gets the collection of output column expressions for the DELETE statement.
49
    /// </summary>
50
    /// <value>
51
    /// A <see cref="HashSet{ColumnExpression}"/> containing the output column expressions.
52
    /// </value>
53
    protected HashSet<ColumnExpression> OutputExpressions { get; } = new();
18✔
54

55
    /// <summary>
56
    /// Gets the collection of FROM table expressions for the DELETE statement.
57
    /// </summary>
58
    /// <value>
59
    /// A <see cref="HashSet{TableExpression}"/> containing the FROM table expressions.
60
    /// </value>
61
    protected HashSet<TableExpression> FromExpressions { get; } = new();
13✔
62

63
    /// <summary>
64
    /// Gets the collection of JOIN expressions for the DELETE statement.
65
    /// </summary>
66
    /// <value>
67
    /// A <see cref="HashSet{JoinExpression}"/> containing the JOIN expressions.
68
    /// </value>
69
    protected HashSet<JoinExpression> JoinExpressions { get; } = new();
13✔
70

71
    /// <summary>
72
    /// Gets the target table expression for the DELETE statement.
73
    /// </summary>
74
    /// <value>
75
    /// The <see cref="TableExpression"/> representing the target table.
76
    /// </value>
77
    protected TableExpression? TableExpression { get; private set; }
24✔
78

79
    /// <summary>
80
    /// Sets the target table to delete from.
81
    /// </summary>
82
    /// <param name="tableName">The name of the table.</param>
83
    /// <param name="tableSchema">The schema of the table (optional).</param>
84
    /// <param name="tableAlias">The alias for the table (optional).</param>
85
    /// <returns>
86
    /// The same builder instance for method chaining.
87
    /// </returns>
88
    public TBuilder Table(
89
        string tableName,
90
        string? tableSchema = null,
91
        string? tableAlias = null)
92
    {
93
        TableExpression = new TableExpression(tableName, tableSchema, tableAlias);
6✔
94

95
        return (TBuilder)this;
6✔
96
    }
97

98
    /// <summary>
99
    /// Adds an OUTPUT clause for the specified column names.
100
    /// </summary>
101
    /// <param name="columnNames">The collection of column names to include in the OUTPUT clause.</param>
102
    /// <param name="tableAlias">The alias for the table (optional).</param>
103
    /// <returns>
104
    /// The same builder instance for method chaining.
105
    /// </returns>
106
    /// <exception cref="ArgumentNullException">Thrown if <paramref name="columnNames"/> is <c>null</c>.</exception>
107
    public TBuilder Output(
108
        IEnumerable<string> columnNames,
109
        string? tableAlias = null)
110
    {
111
        if (columnNames is null)
×
112
            throw new ArgumentNullException(nameof(columnNames));
×
113

114
        foreach (var column in columnNames)
×
115
            Output(column, tableAlias);
×
116

117
        return (TBuilder)this;
×
118
    }
119

120
    /// <summary>
121
    /// Adds an OUTPUT clause for the specified column name.
122
    /// </summary>
123
    /// <param name="columnName">The name of the column to include in the OUTPUT clause.</param>
124
    /// <param name="tableAlias">The alias for the table (optional).</param>
125
    /// <param name="columnAlias">The alias for the column (optional).</param>
126
    /// <returns>
127
    /// The same builder instance for method chaining.
128
    /// </returns>
129
    public TBuilder Output(
130
        string columnName,
131
        string? tableAlias = null,
132
        string? columnAlias = null)
133
    {
134
        var outputClause = new ColumnExpression(columnName, tableAlias, columnAlias);
6✔
135

136
        OutputExpressions.Add(outputClause);
6✔
137

138
        return (TBuilder)this;
6✔
139
    }
140

141
    /// <summary>
142
    /// Conditionally adds an OUTPUT clause for the specified column name if the condition is met.
143
    /// </summary>
144
    /// <param name="columnName">The name of the column to include in the OUTPUT clause.</param>
145
    /// <param name="tableAlias">The alias for the table (optional).</param>
146
    /// <param name="columnAlias">The alias for the column (optional).</param>
147
    /// <param name="condition">A function that determines whether to add the OUTPUT clause. If <c>null</c>, the clause is always added.</param>
148
    /// <returns>
149
    /// The same builder instance for method chaining.
150
    /// </returns>
151
    public TBuilder OutputIf(
152
        string columnName,
153
        string? tableAlias = null,
154
        string? columnAlias = null,
155
        Func<string, bool>? condition = null)
156
    {
157
        if (condition != null && !condition(columnName))
×
158
            return (TBuilder)this;
×
159

160
        return Output(columnName, tableAlias, columnAlias);
×
161
    }
162

163
    /// <summary>
164
    /// Adds a FROM clause to the DELETE statement.
165
    /// </summary>
166
    /// <param name="tableName">The name of the table to include in the FROM clause.</param>
167
    /// <param name="tableSchema">The schema of the table (optional).</param>
168
    /// <param name="tableAlias">The alias for the table (optional).</param>
169
    /// <returns>
170
    /// The same builder instance for method chaining.
171
    /// </returns>
172
    public virtual TBuilder From(
173
        string tableName,
174
        string? tableSchema = null,
175
        string? tableAlias = null)
176
    {
177
        var fromClause = new TableExpression(tableName, tableSchema, tableAlias);
1✔
178

179
        FromExpressions.Add(fromClause);
1✔
180

181
        return (TBuilder)this;
1✔
182
    }
183

184
    /// <summary>
185
    /// Adds a raw FROM clause to the DELETE statement.
186
    /// </summary>
187
    /// <param name="fromClause">The raw SQL FROM clause.</param>
188
    /// <returns>
189
    /// The same builder instance for method chaining.
190
    /// </returns>
191
    public TBuilder FromRaw(string fromClause)
192
    {
193
        if (fromClause.HasValue())
×
194
            FromExpressions.Add(new TableExpression(fromClause, IsRaw: true));
×
195

196
        return (TBuilder)this;
×
197
    }
198

199
    /// <summary>
200
    /// Adds a JOIN clause to the DELETE statement using the specified builder action.
201
    /// </summary>
202
    /// <param name="builder">An action that configures the join using a <see cref="JoinBuilder"/>.</param>
203
    /// <returns>
204
    /// The same builder instance for method chaining.
205
    /// </returns>
206
    public TBuilder Join(Action<JoinBuilder> builder)
207
    {
208
        var innerBuilder = new JoinBuilder(QueryGenerator, Parameters);
×
209
        builder(innerBuilder);
×
210

211
        JoinExpressions.Add(innerBuilder.BuildExpression());
×
212

213
        return (TBuilder)this;
×
214
    }
215

216
    /// <summary>
217
    /// Builds the SQL DELETE statement using the current configuration.
218
    /// </summary>
219
    /// <returns>
220
    /// A <see cref="QueryStatement"/> containing the SQL DELETE statement and its parameters.
221
    /// </returns>
222
    public override QueryStatement? BuildStatement()
223
    {
224
        if (TableExpression is null)
6!
NEW
225
            throw new InvalidOperationException("Table must be specified before building a delete statement.");
×
226

227
        var deleteStatement = new DeleteStatement(
6✔
228
            TableExpression,
6✔
229
            OutputExpressions,
6✔
230
            FromExpressions,
6✔
231
            JoinExpressions,
6✔
232
            WhereExpressions,
6✔
233
            CommentExpressions);
6✔
234

235
        var statement = QueryGenerator.BuildDelete(deleteStatement);
6✔
236

237
        return new QueryStatement(statement, Parameters);
6✔
238
    }
239
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc