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

stephenafamo / bob / 15440741732

04 Jun 2025 11:09AM UTC coverage: 36.99% (-0.002%) from 36.992%
15440741732

Pull #444

github

stephenafamo
Fix issue with factory code gen for tables with schema
Pull Request #444: FIx issues with factory code gen

3 of 6 new or added lines in 6 files covered. (50.0%)

1 existing line in 1 file now uncovered.

8113 of 21933 relevant lines covered (36.99%)

190.09 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/mappings"
13
        "github.com/stephenafamo/bob/orm"
14
)
15

16
type setter[T any] = orm.Setter[T, *dialect.InsertQuery, *dialect.UpdateQuery]
17

18
func NewTable[T any, Tset setter[T]](schema, tableName string) *Table[T, []T, Tset] {
×
19
        return NewTablex[T, []T, Tset](schema, tableName)
×
20
}
×
21

22
func NewTablex[T any, Tslice ~[]T, Tset setter[T]](schema, tableName string) *Table[T, Tslice, Tset] {
×
23
        setMapping := mappings.GetMappings(reflect.TypeOf(*new(Tset)))
×
24
        view, mappings := newView[T, Tslice](schema, tableName)
×
25
        t := &Table[T, Tslice, Tset]{
×
26
                View:          view,
×
NEW
27
                pkCols:        orm.NewColumns(mappings.PKs...).WithParent(view.alias),
×
28
                setterMapping: setMapping,
×
29
        }
×
30

×
31
        return t
×
32
}
×
33

34
// The table contains extract information from the struct and contains
35
// caches ???
36
type Table[T any, Tslice ~[]T, Tset setter[T]] struct {
37
        *View[T, Tslice]
38
        pkCols        orm.Columns
39
        setterMapping mappings.Mapping
40

41
        BeforeInsertHooks bob.Hooks[Tset, bob.SkipModelHooksKey]
42
        AfterInsertHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
43

44
        BeforeUpdateHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
45
        AfterUpdateHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
46

47
        BeforeDeleteHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
48
        AfterDeleteHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
49

50
        InsertQueryHooks bob.Hooks[*dialect.InsertQuery, bob.SkipQueryHooksKey]
51
        UpdateQueryHooks bob.Hooks[*dialect.UpdateQuery, bob.SkipQueryHooksKey]
52
        DeleteQueryHooks bob.Hooks[*dialect.DeleteQuery, bob.SkipQueryHooksKey]
53
}
54

55
// Returns the primary key columns for this table.
56
func (t *Table[T, Tslice, Tset]) PrimaryKey() orm.Columns {
×
57
        return t.pkCols
×
58
}
×
59

60
// Starts an insert query for this table
61
func (t *Table[T, Tslice, Tset]) Insert(queryMods ...bob.Mod[*dialect.InsertQuery]) *orm.Query[*dialect.InsertQuery, T, Tslice] {
×
62
        q := &orm.Query[*dialect.InsertQuery, T, Tslice]{
×
63
                ExecQuery: orm.ExecQuery[*dialect.InsertQuery]{
×
64
                        BaseQuery: Insert(im.Into(t.NameAs())),
×
65
                        Hooks:     &t.InsertQueryHooks,
×
66
                },
×
67
                Scanner: t.scanner,
×
68
        }
×
69

×
70
        q.Expression.AppendContextualModFunc(
×
71
                func(ctx context.Context, q *dialect.InsertQuery) (context.Context, error) {
×
72
                        if !q.HasReturning() {
×
73
                                q.AppendReturning(t.returningCols)
×
74
                        }
×
75
                        return ctx, nil
×
76
                },
77
        )
78

79
        q.Apply(queryMods...)
×
80

×
81
        return q
×
82
}
83

84
// Starts an Update query for this table
85
func (t *Table[T, Tslice, Tset]) Update(queryMods ...bob.Mod[*dialect.UpdateQuery]) *orm.Query[*dialect.UpdateQuery, T, Tslice] {
×
86
        q := &orm.Query[*dialect.UpdateQuery, T, Tslice]{
×
87
                ExecQuery: orm.ExecQuery[*dialect.UpdateQuery]{
×
88
                        BaseQuery: Update(um.Table(t.NameAs())),
×
89
                        Hooks:     &t.UpdateQueryHooks,
×
90
                },
×
91
                Scanner: t.scanner,
×
92
        }
×
93

×
94
        q.Expression.AppendContextualModFunc(
×
95
                func(ctx context.Context, q *dialect.UpdateQuery) (context.Context, error) {
×
96
                        if !q.HasReturning() {
×
97
                                q.AppendReturning(t.returningCols)
×
98
                        }
×
99
                        return ctx, nil
×
100
                },
101
        )
102

103
        q.Apply(queryMods...)
×
104

×
105
        return q
×
106
}
107

108
// Starts a Delete query for this table
109
func (t *Table[T, Tslice, Tset]) Delete(queryMods ...bob.Mod[*dialect.DeleteQuery]) *orm.Query[*dialect.DeleteQuery, T, Tslice] {
×
110
        q := &orm.Query[*dialect.DeleteQuery, T, Tslice]{
×
111
                ExecQuery: orm.ExecQuery[*dialect.DeleteQuery]{
×
112
                        BaseQuery: Delete(dm.From(t.NameAs())),
×
113
                        Hooks:     &t.DeleteQueryHooks,
×
114
                },
×
115
                Scanner: t.scanner,
×
116
        }
×
117

×
118
        q.Expression.AppendContextualModFunc(
×
119
                func(ctx context.Context, q *dialect.DeleteQuery) (context.Context, error) {
×
120
                        if !q.HasReturning() {
×
121
                                q.AppendReturning(t.returningCols)
×
122
                        }
×
123
                        return ctx, nil
×
124
                },
125
        )
126

127
        q.Apply(queryMods...)
×
128

×
129
        return q
×
130
}
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