-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
783 lines (709 loc) · 20.8 KB
/
api.go
File metadata and controls
783 lines (709 loc) · 20.8 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
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
// Package soy provides a type-safe, schema-validated query builder for PostgreSQL.
//
// Soy wraps ASTQL to offer a simplified API for building SQL queries with compile-time
// type safety and runtime schema validation. It uses reflection (via Sentinel) once at
// initialization, then provides a zero-allocation query building API.
//
// # Quick Start
//
// Define your model with struct tags:
//
// type User struct {
// ID int `db:"id" type:"integer" constraints:"primarykey"`
// Email string `db:"email" type:"text" constraints:"notnull,unique"`
// Name string `db:"name" type:"text"`
// Age *int `db:"age" type:"integer"`
// }
//
// Create a Soy instance:
//
// soy, err := soy.New[User](db, "users")
// if err != nil {
// log.Fatal(err)
// }
//
// Build and execute queries:
//
// // Select single record
// user, err := soy.Select().
// Where("email", "=", "user_email").
// Exec(ctx, map[string]any{"user_email": "test@example.com"})
//
// // Query multiple records
// users, err := soy.Query().
// Where("age", ">=", "min_age").
// OrderBy("name", "ASC").
// Limit(10).
// Exec(ctx, map[string]any{"min_age": 18})
//
// // Insert with upsert
// user := &User{Email: "test@example.com", Name: "Test"}
// inserted, err := soy.Insert().
// OnConflict("email").
// DoUpdate().
// Set("name", "name").
// Build().
// Exec(ctx, user)
//
// // Update
// updated, err := soy.Modify().
// Set("name", "new_name").
// Where("id", "=", "user_id").
// Exec(ctx, map[string]any{"new_name": "John", "user_id": 123})
//
// // Delete
// deleted, err := soy.Remove().
// Where("id", "=", "user_id").
// Exec(ctx, map[string]any{"user_id": 123})
//
// // Aggregates
// count, err := soy.Count().
// Where("status", "=", "active").
// Exec(ctx, map[string]any{"status": "active"})
//
// # Features
//
// - Type-safe query building with compile-time guarantees
// - Runtime schema validation against struct tags
// - Zero reflection on the query hot path
// - Named parameter placeholders for SQL injection safety
// - Batch operations for inserts, updates, and deletes
// - Aggregate functions (COUNT, SUM, AVG, MIN, MAX)
// - Complex WHERE conditions with AND/OR grouping
// - DBML schema generation from struct tags
// - Integration with capitan for structured logging
package soy
import (
"context"
"fmt"
"strings"
"github.com/jmoiron/sqlx"
"github.com/zoobz-io/astql"
"github.com/zoobz-io/sentinel"
"github.com/zoobz-io/soy/internal/scanner"
)
// CastType represents SQL cast types.
// Re-exported from astql for convenience.
type CastType = astql.CastType
// Cast type constants.
const (
CastText CastType = astql.CastText
CastInteger CastType = astql.CastInteger
CastBigint CastType = astql.CastBigint
CastSmallint CastType = astql.CastSmallint
CastNumeric CastType = astql.CastNumeric
CastReal CastType = astql.CastReal
CastDoublePrecision CastType = astql.CastDoublePrecision
CastBoolean CastType = astql.CastBoolean
CastDate CastType = astql.CastDate
CastTime CastType = astql.CastTime
CastTimestamp CastType = astql.CastTimestamp
CastTimestampTZ CastType = astql.CastTimestampTZ
CastInterval CastType = astql.CastInterval
CastUUID CastType = astql.CastUUID
CastJSON CastType = astql.CastJSON
CastJSONB CastType = astql.CastJSONB
CastBytea CastType = astql.CastBytea
)
// Soy provides a type-safe query API for a specific model type.
// Each instance holds the ASTQL schema and metadata for building validated queries.
type Soy[T any] struct {
db sqlx.ExtContext
tableName string
metadata sentinel.Metadata
instance *astql.ASTQL
sqlRenderer astql.Renderer
scanner *scanner.Scanner
onScan func(ctx context.Context, result *T) error
onRecord func(ctx context.Context, record *T) error
}
// New creates a new Soy instance for type T with the given database connection, table name, and SQL renderer.
// This function performs type inspection via Sentinel and builds the ASTQL schema for validation.
// All reflection and schema building happens once at initialization, not on the hot path.
// If db is nil, the instance can still be used for query building but not execution.
//
// The db parameter accepts sqlx.ExtContext, which is satisfied by both *sqlx.DB and *sqlx.Tx,
// enabling transaction support by passing a transaction instead of a database connection.
//
// Available renderers from astql/pkg:
// - postgres.New() for PostgreSQL
// - mariadb.New() for MariaDB
// - sqlite.New() for SQLite
// - mssql.New() for Microsoft SQL Server
func New[T any](db sqlx.ExtContext, tableName string, renderer astql.Renderer) (*Soy[T], error) {
if tableName == "" {
return nil, ErrEmptyTableName
}
if renderer == nil {
return nil, ErrNilRenderer
}
// Register all tags we use
sentinel.Tag("db")
sentinel.Tag("type")
sentinel.Tag("constraints")
sentinel.Tag("default")
sentinel.Tag("check")
sentinel.Tag("index")
sentinel.Tag("references")
// Inspect type using Sentinel (cached after first call)
metadata := sentinel.Inspect[T]()
// Build DBML from struct metadata
project, err := buildDBMLFromStruct(metadata, tableName)
if err != nil {
return nil, fmt.Errorf("soy: failed to build DBML: %w", err)
}
// Create ASTQL instance for validation
instance, err := astql.NewFromDBML(project)
if err != nil {
return nil, fmt.Errorf("soy: failed to create ASTQL instance: %w", err)
}
// Build scanner for direct atom scanning from database rows
atomScanner, err := scanner.New(metadata)
if err != nil {
return nil, fmt.Errorf("soy: failed to build scanner: %w", err)
}
c := &Soy[T]{
db: db,
tableName: tableName,
metadata: metadata,
instance: instance,
sqlRenderer: renderer,
scanner: atomScanner,
}
return c, nil
}
// execer returns the database connection for query execution.
func (c *Soy[T]) execer() sqlx.ExtContext {
return c.db
}
// TableName returns the table name for this Soy instance.
func (c *Soy[T]) TableName() string {
return c.tableName
}
// getTableName returns the table name (for interface implementation).
func (c *Soy[T]) getTableName() string {
return c.tableName
}
// Metadata returns the Sentinel metadata for type T.
func (c *Soy[T]) Metadata() sentinel.Metadata {
return c.metadata
}
// renderer returns the SQL renderer for query building.
func (c *Soy[T]) renderer() astql.Renderer {
return c.sqlRenderer
}
// atomScanner returns the scanner for direct atom scanning.
func (c *Soy[T]) atomScanner() *scanner.Scanner {
return c.scanner
}
// getMetadata returns the Sentinel metadata for type T.
func (c *Soy[T]) getMetadata() sentinel.Metadata {
return c.metadata
}
// getInstance returns the ASTQL instance.
func (c *Soy[T]) getInstance() *astql.ASTQL {
return c.instance
}
// OnScan registers a callback that fires after scanning a row into *T.
// It is called in Query, Select, Update, and Create execution paths.
func (c *Soy[T]) OnScan(fn func(ctx context.Context, result *T) error) {
c.onScan = fn
}
// OnRecord registers a callback that fires before writing a *T.
// It is called in Create execution paths before the INSERT is executed.
func (c *Soy[T]) OnRecord(fn func(ctx context.Context, record *T) error) {
c.onRecord = fn
}
// callOnScan invokes the onScan callback if registered.
func (c *Soy[T]) callOnScan(ctx context.Context, result any) error {
if c.onScan == nil {
return nil
}
r, ok := result.(*T)
if !ok {
return fmt.Errorf("callOnScan: expected *%T, got %T", new(T), result)
}
return c.onScan(ctx, r)
}
// callOnRecord invokes the onRecord callback if registered.
func (c *Soy[T]) callOnRecord(ctx context.Context, record any) error {
if c.onRecord == nil {
return nil
}
r, ok := record.(*T)
if !ok {
return fmt.Errorf("callOnRecord: expected *%T, got %T", new(T), record)
}
return c.onRecord(ctx, r)
}
// Instance returns the underlying ASTQL instance for advanced query building.
// Use this escape hatch when you need ASTQL features not exposed by the s.
//
// Example:
//
// instance := soy.Instance()
// query := astql.Select(instance.T("users")).
// Fields(instance.F("id"), instance.F("email")).
// Where(instance.C(instance.F("age"), ">=", instance.P("min_age")))
func (c *Soy[T]) Instance() *astql.ASTQL {
return c.instance
}
// Select returns a Select for building SELECT queries that return a single record.
// The is pre-configured with the table for this Soy instance
// and provides a simple string-based API that hides ASTQL complexity.
//
// Example with Render (for inspection):
//
// result, err := soy.Select().
// Fields("id", "email", "name").
// Where("id", "=", "user_id").
// Render()
//
// Example with Exec (execute and return single T):
//
// user, err := soy.Select().
// Where("email", "=", "user_email").
// Exec(ctx, map[string]any{"user_email": "test@example.com"})
//
// For complex queries with AND/OR logic:
//
// user, err := soy.Select().
// WhereAnd(
// soy.C("age", ">=", "min_age"),
// soy.C("status", "=", "active"),
// ).
// Exec(ctx, params)
//
// For advanced ASTQL features not exposed by Select, use Instance():
//
// instance := .Instance()
// // Use instance.F(), instance.C(), etc. for advanced queries
func (c *Soy[T]) Select() *Select[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
// Table should always be valid since it was validated in New()
// Return with error stored
return &Select[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Select(t)
return &Select[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// Query returns a Query for building SELECT queries that return multiple records.
// The is pre-configured with the table for this Soy instance
// and provides a simple string-based API that hides ASTQL complexity.
//
// Example (basic query):
//
// users, err := soy.Query().
// Where("age", ">=", "min_age").
// OrderBy("name", "ASC").
// Exec(ctx, map[string]any{"min_age": 18})
//
// Example (with pagination):
//
// users, err := soy.Query().
// Where("status", "=", "active").
// OrderBy("created_at", "DESC").
// Limit(10).
// Offset(20).
// Exec(ctx, params)
//
// Example (complex conditions):
//
// users, err := soy.Query().
// WhereAnd(
// soy.C("age", ">=", "min_age"),
// soy.C("status", "=", "active"),
// ).
// Exec(ctx, params)
func (c *Soy[T]) Query() *Query[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
// Table should always be valid since it was validated in New()
// Return with error stored
return &Query[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Select(t)
return &Query[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// Count returns an Aggregate for building COUNT queries.
// The builder is pre-configured with the table for this Soy instance
// and provides a simple string-based API for counting records.
//
// Example (count all):
//
// count, err := soy.Count().Exec(ctx, nil)
//
// Example (count with conditions):
//
// count, err := soy.Count().
// Where("age", ">=", "min_age").
// Where("status", "=", "active").
// Exec(ctx, map[string]any{"min_age": 18, "status": "active"})
func (c *Soy[T]) Count() *Aggregate[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
// Table should always be valid since it was validated in New()
// Return builder with error stored
return &Aggregate[T]{
agg: &aggregateBuilder[T]{
instance: c.instance,
soy: c,
funcName: "COUNT",
err: newTableError(c.tableName, err),
},
}
}
// Build COUNT query
builder := astql.Count(t)
return &Aggregate[T]{
agg: newAggregateBuilder[T](c.instance, builder, c, "", "COUNT"),
}
}
// Sum returns an Aggregate for building SUM aggregate queries.
// Returns the sum of the specified field for matching records.
//
// Example:
//
// total, err := soy.Sum("amount").
// Where("status", "=", "paid").
// Exec(ctx, map[string]any{"status": "paid"})
func (c *Soy[T]) Sum(field string) *Aggregate[T] {
return c.buildFieldAggregate(field, "SUM")
}
// Avg returns an Aggregate for building AVG aggregate queries.
// Returns the average of the specified field for matching records.
//
// Example:
//
// average, err := soy.Avg("age").
// Where("status", "=", "active").
// Exec(ctx, map[string]any{"status": "active"})
func (c *Soy[T]) Avg(field string) *Aggregate[T] {
return c.buildFieldAggregate(field, "AVG")
}
// Min returns an Aggregate for building MIN aggregate queries.
// Returns the minimum value of the specified field for matching records.
//
// Example:
//
// minPrice, err := soy.Min("price").
// Where("category", "=", "electronics").
// Exec(ctx, map[string]any{"category": "electronics"})
func (c *Soy[T]) Min(field string) *Aggregate[T] {
return c.buildFieldAggregate(field, "MIN")
}
// Max returns an Aggregate for building MAX aggregate queries.
// Returns the maximum value of the specified field for matching records.
//
// Example:
//
// maxPrice, err := soy.Max("price").
// Where("category", "=", "electronics").
// Exec(ctx, map[string]any{"category": "electronics"})
func (c *Soy[T]) Max(field string) *Aggregate[T] {
return c.buildFieldAggregate(field, "MAX")
}
// buildFieldAggregate is a helper to build field-based aggregate queries (SUM, AVG, MIN, MAX).
func (c *Soy[T]) buildFieldAggregate(field, funcName string) *Aggregate[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
return &Aggregate[T]{
agg: &aggregateBuilder[T]{
instance: c.instance,
soy: c,
field: field,
funcName: funcName,
err: newTableError(c.tableName, err),
},
}
}
f, err := c.instance.TryF(field)
if err != nil {
return &Aggregate[T]{
agg: &aggregateBuilder[T]{
instance: c.instance,
soy: c,
field: field,
funcName: funcName,
err: newFieldError(field, err),
},
}
}
// Build the appropriate aggregate expression based on funcName
var builder *astql.Builder
switch funcName {
case "SUM":
builder = astql.Select(t).SelectExpr(astql.Sum(f))
case "AVG":
builder = astql.Select(t).SelectExpr(astql.Avg(f))
case "MIN":
builder = astql.Select(t).SelectExpr(astql.Min(f))
case "MAX":
builder = astql.Select(t).SelectExpr(astql.Max(f))
default:
return &Aggregate[T]{
agg: &aggregateBuilder[T]{
instance: c.instance,
soy: c,
field: field,
funcName: funcName,
err: newAggregateFuncError(funcName),
},
}
}
return &Aggregate[T]{
agg: newAggregateBuilder[T](c.instance, builder, c, field, funcName),
}
}
// Insert returns a Create for building INSERT queries.
// The is pre-configured to insert into the table for this Soy instance
// and automatically sets up VALUES from the struct fields and RETURNING all columns.
//
// Example (simple insert):
//
// user := &User{Email: "test@example.com", Name: "Test"}
// inserted, err := soy.Insert().Exec(ctx, user)
//
// Example (upsert with ON CONFLICT):
//
// user := &User{Email: "test@example.com", Name: "Test"}
// inserted, err := soy.Insert().
// OnConflict("email").
// DoUpdate().
// Set("name", "name").
// Exec(ctx, user)
func (c *Soy[T]) Insert() *Create[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Insert(t)
// Build VALUES map using factory - include all non-PK columns
values := c.instance.ValueMap()
for _, field := range c.metadata.Fields {
dbCol := field.Tags["db"]
if dbCol == "" || dbCol == "-" {
continue
}
// Skip primary key columns (they're usually auto-generated)
constraints := field.Tags["constraints"]
if contains(constraints, "primarykey") || contains(constraints, "primary_key") {
continue
}
f, err := c.instance.TryF(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newFieldError(dbCol, err),
}
}
p, err := c.instance.TryP(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newParamError(dbCol, err),
}
}
values[f] = p
}
builder = builder.Values(values)
// Add RETURNING for all columns (to get generated PKs, defaults, etc.)
for _, field := range c.metadata.Fields {
dbCol := field.Tags["db"]
if dbCol == "" || dbCol == "-" {
continue
}
f, err := c.instance.TryF(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newFieldError(dbCol, err),
}
}
builder = builder.Returning(f)
}
return &Create[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// InsertFull returns a Create for building INSERT queries that include primary key columns.
// Use this for upserts where you need to specify the primary key value for ON CONFLICT matching.
//
// Example (upsert with specified PK):
//
// user := &User{ID: 123, Email: "test@example.com", Name: "Test"}
// upserted, err := soy.InsertFull().
// OnConflict("id").
// DoUpdate().
// Set("name", "name").
// Set("email", "email").
// Build().
// Exec(ctx, user)
func (c *Soy[T]) InsertFull() *Create[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Insert(t)
// Build VALUES map including ALL columns (including PK)
values := c.instance.ValueMap()
for _, field := range c.metadata.Fields {
dbCol := field.Tags["db"]
if dbCol == "" || dbCol == "-" {
continue
}
f, err := c.instance.TryF(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newFieldError(dbCol, err),
}
}
p, err := c.instance.TryP(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newParamError(dbCol, err),
}
}
values[f] = p
}
builder = builder.Values(values)
// Add RETURNING for all columns
for _, field := range c.metadata.Fields {
dbCol := field.Tags["db"]
if dbCol == "" || dbCol == "-" {
continue
}
f, err := c.instance.TryF(dbCol)
if err != nil {
return &Create[T]{
instance: c.instance,
soy: c,
err: newFieldError(dbCol, err),
}
}
builder = builder.Returning(f)
}
return &Create[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// Modify returns an Update for building UPDATE queries.
// The is pre-configured with the table for this Soy instance
// and automatically adds RETURNING for all columns.
//
// IMPORTANT: You must add at least one WHERE condition to prevent accidental full-table updates.
//
// Example:
//
// params := map[string]any{
// "new_name": "Updated Name",
// "new_age": 30,
// "user_id": 123,
// }
// updated, err := soy.Modify().
// Set("name", "new_name").
// Set("age", "new_age").
// Where("id", "=", "user_id").
// Exec(ctx, params)
func (c *Soy[T]) Modify() *Update[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
return &Update[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Update(t)
// Only add RETURNING if the renderer supports it (e.g., PostgreSQL, SQLite, MSSQL).
// MariaDB doesn't support RETURNING on UPDATE, so exec() will use a fallback SELECT.
if c.renderer().Capabilities().ReturningOnUpdate {
for _, field := range c.metadata.Fields {
dbCol := field.Tags["db"]
if dbCol == "" || dbCol == "-" {
continue
}
f, err := c.instance.TryF(dbCol)
if err != nil {
return &Update[T]{
instance: c.instance,
soy: c,
err: newFieldError(dbCol, err),
}
}
builder = builder.Returning(f)
}
}
return &Update[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// Remove returns a Delete for building DELETE queries.
// The is pre-configured with the table for this Soy instance.
//
// IMPORTANT: You must add at least one WHERE condition to prevent accidental full-table deletes.
//
// Example:
//
// params := map[string]any{"user_id": 123}
// rowsDeleted, err := soy.Remove().
// Where("id", "=", "user_id").
// Exec(ctx, params)
func (c *Soy[T]) Remove() *Delete[T] {
t, err := c.instance.TryT(c.tableName)
if err != nil {
return &Delete[T]{
instance: c.instance,
soy: c,
err: newTableError(c.tableName, err),
}
}
builder := astql.Delete(t)
return &Delete[T]{
instance: c.instance,
builder: builder,
soy: c,
}
}
// contains checks if a string contains a substring (case-insensitive).
func contains(s, substr string) bool {
return strings.Contains(strings.ToLower(s), strings.ToLower(substr))
}