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

stephenafamo / bob / 28859876462

07 Jul 2026 10:36AM UTC coverage: 47.665% (+0.5%) from 47.129%
28859876462

push

github

web-flow
Merge pull request #715 from sandonemaki/perf/loader-typed-scan

perf(gen): generate typed scan mappers and inject them via the model constructors

41 of 56 new or added lines in 10 files covered. (73.21%)

3 existing lines in 3 files now uncovered.

11839 of 24838 relevant lines covered (47.66%)

721.81 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/expr"
13
        "github.com/stephenafamo/bob/internal/mappings"
14
        "github.com/stephenafamo/bob/orm"
15
        "github.com/stephenafamo/scan"
16
)
17

18
type (
19
        setter[T any]                      = orm.Setter[T, *dialect.InsertQuery, *dialect.UpdateQuery]
20
        ormInsertQuery[T any, Tslice ~[]T] = orm.Query[*dialect.InsertQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
21
        ormUpdateQuery[T any, Tslice ~[]T] = orm.Query[*dialect.UpdateQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
22
        ormDeleteQuery[T any, Tslice ~[]T] = orm.Query[*dialect.DeleteQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
23
)
24

25
func NewTable[T any, Tset setter[T], C bob.Expression](schema, tableName string, columns C) *Table[T, []T, Tset, C] {
×
NEW
26
        return NewTablex[T, []T, Tset](schema, tableName, columns, nil)
×
27
}
×
28

29
// NewTablex creates a new Table with a custom scanner.
30
// If scanner is nil, it falls back to [scan.StructMapper].
NEW
31
func NewTablex[T any, Tslice ~[]T, Tset setter[T], C bob.Expression](schema, tableName string, columns C, scanner scan.Mapper[T]) *Table[T, Tslice, Tset, C] {
×
32
        setMapping := mappings.GetMappings(reflect.TypeOf(*new(Tset)))
×
NEW
33
        view, mappings := newView[T, Tslice](schema, tableName, columns, scanner)
×
34
        t := &Table[T, Tslice, Tset, C]{
×
35
                View:          view,
×
36
                pkCols:        expr.NewColumnsExpr(mappings.PKs...).WithParent(view.alias),
×
37
                setterMapping: setMapping,
×
38
        }
×
39

×
40
        return t
×
41
}
×
42

43
// The table contains extract information from the struct and contains
44
// caches ???
45
type Table[T any, Tslice ~[]T, Tset setter[T], C bob.Expression] struct {
46
        *View[T, Tslice, C]
47
        pkCols        expr.ColumnsExpr
48
        setterMapping mappings.Mapping
49

50
        BeforeInsertHooks bob.Hooks[Tset, bob.SkipModelHooksKey]
51
        AfterInsertHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
52

53
        BeforeUpdateHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
54
        AfterUpdateHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
55

56
        BeforeDeleteHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
57
        AfterDeleteHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
58

59
        InsertQueryHooks bob.Hooks[*dialect.InsertQuery, bob.SkipQueryHooksKey]
60
        UpdateQueryHooks bob.Hooks[*dialect.UpdateQuery, bob.SkipQueryHooksKey]
61
        DeleteQueryHooks bob.Hooks[*dialect.DeleteQuery, bob.SkipQueryHooksKey]
62
}
63

64
// Returns the primary key columns for this table.
65
func (t *Table[T, Tslice, Tset, C]) PrimaryKey() expr.ColumnsExpr {
×
66
        return t.pkCols
×
67
}
×
68

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

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

88
        q.Apply(queryMods...)
×
89

×
90
        return q
×
91
}
92

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

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

112
        q.Apply(queryMods...)
×
113

×
114
        return q
×
115
}
116

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

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

136
        q.Apply(queryMods...)
×
137

×
138
        return q
×
139
}
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