-
Notifications
You must be signed in to change notification settings - Fork 8
/
update_query.go
653 lines (568 loc) · 20.5 KB
/
update_query.go
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package sq
import (
"bytes"
"context"
"fmt"
)
// UpdateQuery represents an SQL UPDATE query.
type UpdateQuery struct {
Dialect string
ColumnMapper func(*Column)
// WITH
CTEs []CTE
// UPDATE
UpdateTable Table
// FROM
FromTable Table
JoinTables []JoinTable
// SET
Assignments []Assignment
// WHERE
WherePredicate Predicate
// ORDER BY
OrderByFields []Field
// LIMIT
LimitRows any
// RETURNING
ReturningFields []Field
}
var _ Query = (*UpdateQuery)(nil)
// WriteSQL implements the SQLWriter interface.
func (q UpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) (err error) {
if q.ColumnMapper != nil {
col := &Column{
dialect: q.Dialect,
isUpdate: true,
}
defer mapperFunctionPanicked(&err)
q.ColumnMapper(col)
if err != nil {
return err
}
q.Assignments = col.assignments
}
// Table Policies
var policies []Predicate
policies, err = appendPolicy(ctx, dialect, policies, q.UpdateTable)
if err != nil {
return fmt.Errorf("UPDATE %s Policy: %w", toString(q.Dialect, q.UpdateTable), err)
}
policies, err = appendPolicy(ctx, dialect, policies, q.FromTable)
if err != nil {
return fmt.Errorf("FROM %s Policy: %w", toString(q.Dialect, q.FromTable), err)
}
for _, joinTable := range q.JoinTables {
policies, err = appendPolicy(ctx, dialect, policies, joinTable.Table)
if err != nil {
return fmt.Errorf("%s %s Policy: %w", joinTable.JoinOperator, joinTable.Table, err)
}
}
if len(policies) > 0 {
if q.WherePredicate != nil {
policies = append(policies, q.WherePredicate)
}
q.WherePredicate = And(policies...)
}
// WITH
if len(q.CTEs) > 0 {
err = writeCTEs(ctx, dialect, buf, args, params, q.CTEs)
if err != nil {
return fmt.Errorf("WITH: %w", err)
}
}
// UPDATE
buf.WriteString("UPDATE ")
if q.UpdateTable == nil {
return fmt.Errorf("no table provided to UPDATE")
}
err = q.UpdateTable.WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("UPDATE: %w", err)
}
if dialect != DialectSQLServer {
if alias := getAlias(q.UpdateTable); alias != "" {
buf.WriteString(" AS " + QuoteIdentifier(dialect, alias))
}
}
if len(q.Assignments) == 0 {
return fmt.Errorf("no fields to update")
}
// SET (not mysql)
if dialect != DialectMySQL {
buf.WriteString(" SET ")
err = Assignments(q.Assignments).WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("SET: %w", err)
}
}
// OUTPUT
if len(q.ReturningFields) > 0 && dialect == DialectSQLServer {
buf.WriteString(" OUTPUT ")
err = writeFieldsWithPrefix(ctx, dialect, buf, args, params, q.ReturningFields, "INSERTED", true)
if err != nil {
return err
}
}
// FROM
if q.FromTable != nil {
if dialect == DialectMySQL {
return fmt.Errorf("mysql UPDATE does not support FROM")
}
buf.WriteString(" FROM ")
err = q.FromTable.WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("FROM: %w", err)
}
if alias := getAlias(q.FromTable); alias != "" {
buf.WriteString(" AS " + QuoteIdentifier(dialect, alias) + quoteTableColumns(dialect, q.FromTable))
}
}
// JOIN
if len(q.JoinTables) > 0 {
if q.FromTable == nil && dialect != DialectMySQL {
return fmt.Errorf("%s can't JOIN without a FROM table", dialect)
}
buf.WriteString(" ")
err = writeJoinTables(ctx, dialect, buf, args, params, q.JoinTables)
if err != nil {
return fmt.Errorf("JOIN: %w", err)
}
}
// SET (mysql)
if dialect == DialectMySQL {
buf.WriteString(" SET ")
err = Assignments(q.Assignments).WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("SET: %w", err)
}
}
// WHERE
if q.WherePredicate != nil {
buf.WriteString(" WHERE ")
switch predicate := q.WherePredicate.(type) {
case VariadicPredicate:
predicate.Toplevel = true
err = predicate.WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("WHERE: %w", err)
}
default:
err = q.WherePredicate.WriteSQL(ctx, dialect, buf, args, params)
if err != nil {
return fmt.Errorf("WHERE: %w", err)
}
}
}
// ORDER BY
if len(q.OrderByFields) > 0 {
if dialect != DialectMySQL {
return fmt.Errorf("%s UPDATE does not support ORDER BY", dialect)
}
buf.WriteString(" ORDER BY ")
err = writeFields(ctx, dialect, buf, args, params, q.OrderByFields, false)
if err != nil {
return fmt.Errorf("ORDER BY: %w", err)
}
}
// LIMIT
if q.LimitRows != nil {
if dialect != DialectMySQL {
return fmt.Errorf("%s UPDATE does not support LIMIT", dialect)
}
buf.WriteString(" LIMIT ")
err = WriteValue(ctx, dialect, buf, args, params, q.LimitRows)
if err != nil {
return fmt.Errorf("LIMIT: %w", err)
}
}
// RETURNING
if len(q.ReturningFields) > 0 && dialect != DialectSQLServer {
if dialect != DialectPostgres && dialect != DialectSQLite {
return fmt.Errorf("%s UPDATE does not support RETURNING", dialect)
}
buf.WriteString(" RETURNING ")
err = writeFields(ctx, dialect, buf, args, params, q.ReturningFields, true)
if err != nil {
return fmt.Errorf("RETURNING: %w", err)
}
}
return nil
}
// Update returns a new UpdateQuery.
func Update(table Table) UpdateQuery {
return UpdateQuery{UpdateTable: table}
}
// Set sets the Assignments field of the UpdateQuery.
func (q UpdateQuery) Set(assignments ...Assignment) UpdateQuery {
q.Assignments = append(q.Assignments, assignments...)
return q
}
// SetFunc sets the ColumnMapper field of the UpdateQuery.
func (q UpdateQuery) SetFunc(colmapper func(*Column)) UpdateQuery {
q.ColumnMapper = colmapper
return q
}
// Where appends to the WherePredicate field of the UpdateQuery.
func (q UpdateQuery) Where(predicates ...Predicate) UpdateQuery {
q.WherePredicate = appendPredicates(q.WherePredicate, predicates)
return q
}
// SetFetchableFields implements the Query interface.
func (q UpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool) {
switch q.Dialect {
case DialectPostgres, DialectSQLite:
if len(q.ReturningFields) == 0 {
q.ReturningFields = fields
return q, true
}
return q, false
default:
return q, false
}
}
// GetFetchableFields returns the fetchable fields of the query.
func (q UpdateQuery) GetFetchableFields() []Field {
switch q.Dialect {
case DialectPostgres, DialectSQLite:
return q.ReturningFields
default:
return nil
}
}
// GetDialect implements the Query interface.
func (q UpdateQuery) GetDialect() string { return q.Dialect }
// SetDialect sets the dialect of the query.
func (q UpdateQuery) SetDialect(dialect string) UpdateQuery {
q.Dialect = dialect
return q
}
// SQLiteUpdateQuery represents an SQLite UPDATE query.
type SQLiteUpdateQuery UpdateQuery
var _ Query = (*SQLiteUpdateQuery)(nil)
// WriteSQL implements the SQLWriter interface.
func (q SQLiteUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error {
return UpdateQuery(q).WriteSQL(ctx, dialect, buf, args, params)
}
// Update returns a new SQLiteUpdateQuery.
func (b sqliteQueryBuilder) Update(table Table) SQLiteUpdateQuery {
return SQLiteUpdateQuery{
Dialect: DialectSQLite,
CTEs: b.ctes,
UpdateTable: table,
}
}
// Set sets the Assignments field of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) Set(assignments ...Assignment) SQLiteUpdateQuery {
q.Assignments = append(q.Assignments, assignments...)
return q
}
// SetFunc sets the ColumnMapper of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) SetFunc(colmapper func(*Column)) SQLiteUpdateQuery {
q.ColumnMapper = colmapper
return q
}
// From sets the FromTable field of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) From(table Table) SQLiteUpdateQuery {
q.FromTable = table
return q
}
// Join joins a new Table to the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) Join(table Table, predicates ...Predicate) SQLiteUpdateQuery {
q.JoinTables = append(q.JoinTables, Join(table, predicates...))
return q
}
// LeftJoin left joins a new Table to the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) LeftJoin(table Table, predicates ...Predicate) SQLiteUpdateQuery {
q.JoinTables = append(q.JoinTables, LeftJoin(table, predicates...))
return q
}
// CrossJoin cross joins a new Table to the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) CrossJoin(table Table) SQLiteUpdateQuery {
q.JoinTables = append(q.JoinTables, CrossJoin(table))
return q
}
// CustomJoin joins a new Table to the SQLiteUpdateQuery with a custom join
// operator.
func (q SQLiteUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLiteUpdateQuery {
q.JoinTables = append(q.JoinTables, CustomJoin(joinOperator, table, predicates...))
return q
}
// JoinUsing joins a new Table to the SQLiteUpdateQuery with the USING operator.
func (q SQLiteUpdateQuery) JoinUsing(table Table, fields ...Field) SQLiteUpdateQuery {
q.JoinTables = append(q.JoinTables, JoinUsing(table, fields...))
return q
}
// Where appends to the WherePredicate field of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) Where(predicates ...Predicate) SQLiteUpdateQuery {
q.WherePredicate = appendPredicates(q.WherePredicate, predicates)
return q
}
// Returning sets the ReturningFields field of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) Returning(fields ...Field) SQLiteUpdateQuery {
q.ReturningFields = append(q.ReturningFields, fields...)
return q
}
// SetFetchableFields implements the Query interface.
func (q SQLiteUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool) {
return UpdateQuery(q).SetFetchableFields(fields)
}
// GetFetchableFields returns the fetchable fields of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) GetFetchableFields() []Field {
return UpdateQuery(q).GetFetchableFields()
}
// GetDialect implements the Query interface.
func (q SQLiteUpdateQuery) GetDialect() string { return q.Dialect }
// SetDialect sets the dialect of the SQLiteUpdateQuery.
func (q SQLiteUpdateQuery) SetDialect(dialect string) SQLiteUpdateQuery {
q.Dialect = dialect
return q
}
// PostgresUpdateQuery represents a Postgres UPDATE query.
type PostgresUpdateQuery UpdateQuery
var _ Query = (*PostgresUpdateQuery)(nil)
// WriteSQL implements the SQLWriter interface.
func (q PostgresUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error {
return UpdateQuery(q).WriteSQL(ctx, dialect, buf, args, params)
}
// Update returns a new PostgresUpdateQuery.
func (b postgresQueryBuilder) Update(table Table) PostgresUpdateQuery {
return PostgresUpdateQuery{
Dialect: DialectPostgres,
CTEs: b.ctes,
UpdateTable: table,
}
}
// Set sets the Assignments field of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) Set(assignments ...Assignment) PostgresUpdateQuery {
q.Assignments = append(q.Assignments, assignments...)
return q
}
// SetFunc sets the ColumnMapper of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) SetFunc(colmapper func(*Column)) PostgresUpdateQuery {
q.ColumnMapper = colmapper
return q
}
// From sets the FromTable field of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) From(table Table) PostgresUpdateQuery {
q.FromTable = table
return q
}
// Join joins a new Table to the PostgresUpdateQuery.
func (q PostgresUpdateQuery) Join(table Table, predicates ...Predicate) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, Join(table, predicates...))
return q
}
// LeftJoin left joins a new Table to the PostgresUpdateQuery.
func (q PostgresUpdateQuery) LeftJoin(table Table, predicates ...Predicate) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, LeftJoin(table, predicates...))
return q
}
// FullJoin full joins a new Table to the PostgresUpdateQuery.
func (q PostgresUpdateQuery) FullJoin(table Table, predicates ...Predicate) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, FullJoin(table, predicates...))
return q
}
// CrossJoin cross joins a new Table to the PostgresUpdateQuery.
func (q PostgresUpdateQuery) CrossJoin(table Table) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, CrossJoin(table))
return q
}
// CustomJoin joins a new Table to the PostgresUpdateQuery with a custom join
// operator.
func (q PostgresUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, CustomJoin(joinOperator, table, predicates...))
return q
}
// JoinUsing joins a new Table to the PostgresUpdateQuery with the USING operator.
func (q PostgresUpdateQuery) JoinUsing(table Table, fields ...Field) PostgresUpdateQuery {
q.JoinTables = append(q.JoinTables, JoinUsing(table, fields...))
return q
}
// Where appends to the WherePredicate field of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) Where(predicates ...Predicate) PostgresUpdateQuery {
q.WherePredicate = appendPredicates(q.WherePredicate, predicates)
return q
}
// Returning sets the ReturningFields field of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) Returning(fields ...Field) PostgresUpdateQuery {
q.ReturningFields = append(q.ReturningFields, fields...)
return q
}
// SetFetchableFields implements the Query interface.
func (q PostgresUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool) {
return UpdateQuery(q).SetFetchableFields(fields)
}
// GetFetchableFields returns the fetchable fields of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) GetFetchableFields() []Field {
return UpdateQuery(q).GetFetchableFields()
}
// GetDialect implements the Query interface.
func (q PostgresUpdateQuery) GetDialect() string { return q.Dialect }
// SetDialect sets the dialect of the PostgresUpdateQuery.
func (q PostgresUpdateQuery) SetDialect(dialect string) PostgresUpdateQuery {
q.Dialect = dialect
return q
}
// MySQLUpdateQuery represents a MySQL UPDATE query.
type MySQLUpdateQuery UpdateQuery
var _ Query = (*MySQLUpdateQuery)(nil)
// WriteSQL implements the SQLWriter interface.
func (q MySQLUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error {
return UpdateQuery(q).WriteSQL(ctx, dialect, buf, args, params)
}
// Update returns a new MySQLUpdateQuery.
func (b mysqlQueryBuilder) Update(table Table) MySQLUpdateQuery {
q := MySQLUpdateQuery{
Dialect: DialectMySQL,
CTEs: b.ctes,
UpdateTable: table,
}
return q
}
// Join joins a new Table to the MySQLUpdateQuery.
func (q MySQLUpdateQuery) Join(table Table, predicates ...Predicate) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, Join(table, predicates...))
return q
}
// LeftJoin left joins a new Table to the MySQLUpdateQuery.
func (q MySQLUpdateQuery) LeftJoin(table Table, predicates ...Predicate) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, LeftJoin(table, predicates...))
return q
}
// FullJoin full joins a new Table to the MySQLUpdateQuery.
func (q MySQLUpdateQuery) FullJoin(table Table, predicates ...Predicate) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, FullJoin(table, predicates...))
return q
}
// CrossJoin cross joins a new Table to the MySQLUpdateQuery.
func (q MySQLUpdateQuery) CrossJoin(table Table) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, CrossJoin(table))
return q
}
// CustomJoin joins a new Table to the MySQLUpdateQuery with a custom join
// operator.
func (q MySQLUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, CustomJoin(joinOperator, table, predicates...))
return q
}
// JoinUsing joins a new Table to the MySQLUpdateQuery with the USING operator.
func (q MySQLUpdateQuery) JoinUsing(table Table, fields ...Field) MySQLUpdateQuery {
q.JoinTables = append(q.JoinTables, JoinUsing(table, fields...))
return q
}
// Set sets the Assignments field of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) Set(assignments ...Assignment) MySQLUpdateQuery {
q.Assignments = append(q.Assignments, assignments...)
return q
}
// SetFunc sets the ColumnMapper of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) SetFunc(colmapper func(*Column)) MySQLUpdateQuery {
q.ColumnMapper = colmapper
return q
}
// Where appends to the WherePredicate field of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) Where(predicates ...Predicate) MySQLUpdateQuery {
q.WherePredicate = appendPredicates(q.WherePredicate, predicates)
return q
}
// OrderBy sets the OrderByFields of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) OrderBy(fields ...Field) MySQLUpdateQuery {
q.OrderByFields = append(q.OrderByFields, fields...)
return q
}
// Limit sets the LimitRows field of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) Limit(limit any) MySQLUpdateQuery {
q.LimitRows = limit
return q
}
// SetFetchableFields implements the Query interface.
func (q MySQLUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool) {
return UpdateQuery(q).SetFetchableFields(fields)
}
// GetFetchableFields returns the fetchable fields of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) GetFetchableFields() []Field {
return UpdateQuery(q).GetFetchableFields()
}
// GetDialect implements the Query interface.
func (q MySQLUpdateQuery) GetDialect() string { return q.Dialect }
// SetDialect sets the dialect of the MySQLUpdateQuery.
func (q MySQLUpdateQuery) SetDialect(dialect string) MySQLUpdateQuery {
q.Dialect = dialect
return q
}
// SQLServerUpdateQuery represents an SQL Server UPDATE query.
type SQLServerUpdateQuery UpdateQuery
var _ Query = (*SQLServerUpdateQuery)(nil)
// WriteSQL implements the SQLWriter interface.
func (q SQLServerUpdateQuery) WriteSQL(ctx context.Context, dialect string, buf *bytes.Buffer, args *[]any, params map[string][]int) error {
return UpdateQuery(q).WriteSQL(ctx, dialect, buf, args, params)
}
// Update returns a new SQLServerUpdateQuery.
func (b sqlserverQueryBuilder) Update(table Table) SQLServerUpdateQuery {
return SQLServerUpdateQuery{
Dialect: DialectSQLServer,
CTEs: b.ctes,
UpdateTable: table,
}
}
// Set sets the Assignments field of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) Set(assignments ...Assignment) SQLServerUpdateQuery {
q.Assignments = append(q.Assignments, assignments...)
return q
}
// SetFunc sets the ColumnMapper of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) SetFunc(colmapper func(*Column)) SQLServerUpdateQuery {
q.ColumnMapper = colmapper
return q
}
// From sets the FromTable field of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) From(table Table) SQLServerUpdateQuery {
q.FromTable = table
return q
}
// Join joins a new Table to the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) Join(table Table, predicates ...Predicate) SQLServerUpdateQuery {
q.JoinTables = append(q.JoinTables, Join(table, predicates...))
return q
}
// LeftJoin left joins a new Table to the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) LeftJoin(table Table, predicates ...Predicate) SQLServerUpdateQuery {
q.JoinTables = append(q.JoinTables, LeftJoin(table, predicates...))
return q
}
// FullJoin full joins a new Table to the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) FullJoin(table Table, predicates ...Predicate) SQLServerUpdateQuery {
q.JoinTables = append(q.JoinTables, FullJoin(table, predicates...))
return q
}
// CrossJoin cross joins a new Table to the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) CrossJoin(table Table) SQLServerUpdateQuery {
q.JoinTables = append(q.JoinTables, CrossJoin(table))
return q
}
// CustomJoin joins a new Table to the SQLServerUpdateQuery with a custom join
// operator.
func (q SQLServerUpdateQuery) CustomJoin(joinOperator string, table Table, predicates ...Predicate) SQLServerUpdateQuery {
q.JoinTables = append(q.JoinTables, CustomJoin(joinOperator, table, predicates...))
return q
}
// Where appends to the WherePredicate field of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) Where(predicates ...Predicate) SQLServerUpdateQuery {
q.WherePredicate = appendPredicates(q.WherePredicate, predicates)
return q
}
// SetFetchableFields implements the Query interface.
func (q SQLServerUpdateQuery) SetFetchableFields(fields []Field) (query Query, ok bool) {
return UpdateQuery(q).SetFetchableFields(fields)
}
// GetFetchableFields returns the fetchable fields of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) GetFetchableFields() []Field {
return UpdateQuery(q).GetFetchableFields()
}
// GetDialect implements the Query interface.
func (q SQLServerUpdateQuery) GetDialect() string { return q.Dialect }
// SetDialect sets the dialect of the SQLServerUpdateQuery.
func (q SQLServerUpdateQuery) SetDialect(dialect string) SQLServerUpdateQuery {
q.Dialect = dialect
return q
}