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

stephenafamo / bob / 15232998264

25 May 2025 01:44AM UTC coverage: 30.996% (+0.5%) from 30.447%
15232998264

Pull #425

github

stephenafamo
Use testcontainers for LibSQL tests
Pull Request #425: WIP: Respect column limits in randomization functions

329 of 481 new or added lines in 22 files covered. (68.4%)

3 existing lines in 2 files now uncovered.

6719 of 21677 relevant lines covered (31.0%)

117.02 hits per line

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

0.0
/dialect/sqlite/table.go
1
package sqlite
2

3
import (
4
        "context"
5
        "reflect"
6

7
        "github.com/stephenafamo/bob"
8
        "github.com/stephenafamo/bob/dialect/sqlite/dialect"
9
        "github.com/stephenafamo/bob/dialect/sqlite/dm"
10
        "github.com/stephenafamo/bob/dialect/sqlite/im"
11
        "github.com/stephenafamo/bob/dialect/sqlite/um"
12
        "github.com/stephenafamo/bob/internal"
13
        "github.com/stephenafamo/bob/internal/mappings"
14
        "github.com/stephenafamo/bob/orm"
15
)
16

17
type setter[T any] interface {
18
        orm.Setter[T, *dialect.InsertQuery, *dialect.UpdateQuery]
19
}
20

21
func NewTable[T orm.Model, Tset setter[T]](schema, tableName string) *Table[T, []T, Tset] {
×
22
        return NewTablex[T, []T, Tset](schema, tableName)
×
23
}
×
24

25
func NewTablex[T orm.Model, Tslice ~[]T, Tset setter[T]](schema, tableName string) *Table[T, Tslice, Tset] {
×
26
        var zeroSet Tset
×
27

×
28
        setMapping := mappings.GetMappings(reflect.TypeOf(zeroSet))
×
29
        view, mappings := newView[T, Tslice](schema, tableName)
×
30
        t := &Table[T, Tslice, Tset]{
×
31
                View:          view,
×
32
                pkCols:        internal.FilterNonZero(mappings.PKs),
×
33
                setterMapping: setMapping,
×
34
        }
×
35

×
36
        if len(t.pkCols) == 1 {
×
37
                t.pkExpr = Quote(t.pkCols[0])
×
38
        } else {
×
39
                expr := make([]bob.Expression, len(t.pkCols))
×
40
                for i, col := range t.pkCols {
×
41
                        expr[i] = Quote(col)
×
42
                }
×
43
                t.pkExpr = Group(expr...)
×
44
        }
45

46
        return t
×
47
}
48

49
// The table contains extract information from the struct and contains
50
// caches ???
51
type Table[T orm.Model, Tslice ~[]T, Tset setter[T]] struct {
52
        *View[T, Tslice]
53
        pkCols        []string
54
        pkExpr        dialect.Expression
55
        setterMapping mappings.Mapping
56

57
        BeforeInsertHooks bob.Hooks[Tset, bob.SkipModelHooksKey]
58
        AfterInsertHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
59

60
        BeforeUpdateHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
61
        AfterUpdateHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
62

63
        BeforeDeleteHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
64
        AfterDeleteHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
65

66
        InsertQueryHooks bob.Hooks[*dialect.InsertQuery, bob.SkipQueryHooksKey]
67
        UpdateQueryHooks bob.Hooks[*dialect.UpdateQuery, bob.SkipQueryHooksKey]
68
        DeleteQueryHooks bob.Hooks[*dialect.DeleteQuery, bob.SkipQueryHooksKey]
69
}
70

71
// Starts an insert query for this table
72
func (t *Table[T, Tslice, Tset]) Insert(queryMods ...bob.Mod[*dialect.InsertQuery]) *orm.Query[*dialect.InsertQuery, T, Tslice] {
×
73
        q := &orm.Query[*dialect.InsertQuery, T, Tslice]{
×
74
                ExecQuery: orm.ExecQuery[*dialect.InsertQuery]{
×
75
                        BaseQuery: Insert(im.Into(t.NameAs())),
×
76
                        Hooks:     &t.InsertQueryHooks,
×
77
                },
×
78
                Scanner: t.scanner,
×
79
        }
×
80

×
81
        q.Expression.AppendContextualModFunc(
×
82
                func(ctx context.Context, q *dialect.InsertQuery) (context.Context, error) {
×
83
                        if !q.HasReturning() {
×
NEW
84
                                q.AppendReturning(t.returningCols)
×
85
                        }
×
86
                        return ctx, nil
×
87
                },
88
        )
89

90
        q.Apply(queryMods...)
×
91

×
92
        return q
×
93
}
94

95
// Starts an Update query for this table
96
func (t *Table[T, Tslice, Tset]) Update(queryMods ...bob.Mod[*dialect.UpdateQuery]) *orm.Query[*dialect.UpdateQuery, T, Tslice] {
×
97
        q := &orm.Query[*dialect.UpdateQuery, T, Tslice]{
×
98
                ExecQuery: orm.ExecQuery[*dialect.UpdateQuery]{
×
99
                        BaseQuery: Update(um.Table(t.NameAs())),
×
100
                        Hooks:     &t.UpdateQueryHooks,
×
101
                },
×
102
                Scanner: t.scanner,
×
103
        }
×
104

×
105
        q.Expression.AppendContextualModFunc(
×
106
                func(ctx context.Context, q *dialect.UpdateQuery) (context.Context, error) {
×
107
                        if !q.HasReturning() {
×
NEW
108
                                q.AppendReturning(t.returningCols)
×
109
                        }
×
110
                        return ctx, nil
×
111
                },
112
        )
113

114
        q.Apply(queryMods...)
×
115

×
116
        return q
×
117
}
118

119
// Starts a Delete query for this table
120
func (t *Table[T, Tslice, Tset]) Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) *orm.Query[*dialect.DeleteQuery, T, Tslice] {
×
121
        q := &orm.Query[*dialect.DeleteQuery, T, Tslice]{
×
122
                ExecQuery: orm.ExecQuery[*dialect.DeleteQuery]{
×
123
                        BaseQuery: Delete(dm.From(t.NameAs())),
×
124
                        Hooks:     &t.DeleteQueryHooks,
×
125
                },
×
126
                Scanner: t.scanner,
×
127
        }
×
128

×
129
        q.Expression.AppendContextualModFunc(
×
130
                func(ctx context.Context, q *dialect.DeleteQuery) (context.Context, error) {
×
131
                        if !q.HasReturning() {
×
NEW
132
                                q.AppendReturning(t.returningCols)
×
133
                        }
×
134
                        return ctx, nil
×
135
                },
136
        )
137

138
        q.Apply(queryMods...)
×
139

×
140
        return q
×
141
}
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