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

stephenafamo / bob / 15646986598

14 Jun 2025 01:31AM UTC coverage: 36.722% (-0.3%) from 37.021%
15646986598

push

github

web-flow
Merge pull request #460 from stephenafamo/nested-query

Nest columns with `.` in query codegen

12 of 234 new or added lines in 13 files covered. (5.13%)

5 existing lines in 2 files now uncovered.

8171 of 22251 relevant lines covered (36.72%)

268.43 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 (
17
        setter[T any]                      = orm.Setter[T, *dialect.InsertQuery, *dialect.UpdateQuery]
18
        ormInsertQuery[T any, Tslice ~[]T] = orm.Query[*dialect.InsertQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
19
        ormUpdateQuery[T any, Tslice ~[]T] = orm.Query[*dialect.UpdateQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
20
        ormDeleteQuery[T any, Tslice ~[]T] = orm.Query[*dialect.DeleteQuery, T, Tslice, bob.SliceTransformer[T, Tslice]]
21
)
22

23
func NewTable[T any, Tset setter[T]](schema, tableName string) *Table[T, []T, Tset] {
×
24
        return NewTablex[T, []T, Tset](schema, tableName)
×
25
}
×
26

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

×
36
        return t
×
37
}
×
38

39
// The table contains extract information from the struct and contains
40
// caches ???
41
type Table[T any, Tslice ~[]T, Tset setter[T]] struct {
42
        *View[T, Tslice]
43
        pkCols        orm.Columns
44
        setterMapping mappings.Mapping
45

46
        BeforeInsertHooks bob.Hooks[Tset, bob.SkipModelHooksKey]
47
        AfterInsertHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
48

49
        BeforeUpdateHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
50
        AfterUpdateHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
51

52
        BeforeDeleteHooks bob.Hooks[Tslice, bob.SkipModelHooksKey]
53
        AfterDeleteHooks  bob.Hooks[Tslice, bob.SkipModelHooksKey]
54

55
        InsertQueryHooks bob.Hooks[*dialect.InsertQuery, bob.SkipQueryHooksKey]
56
        UpdateQueryHooks bob.Hooks[*dialect.UpdateQuery, bob.SkipQueryHooksKey]
57
        DeleteQueryHooks bob.Hooks[*dialect.DeleteQuery, bob.SkipQueryHooksKey]
58
}
59

60
// Returns the primary key columns for this table.
61
func (t *Table[T, Tslice, Tset]) PrimaryKey() orm.Columns {
×
62
        return t.pkCols
×
63
}
×
64

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

×
75
        q.Expression.AppendContextualModFunc(
×
76
                func(ctx context.Context, q *dialect.InsertQuery) (context.Context, error) {
×
77
                        if !q.HasReturning() {
×
78
                                q.AppendReturning(t.returningCols)
×
79
                        }
×
80
                        return ctx, nil
×
81
                },
82
        )
83

84
        q.Apply(queryMods...)
×
85

×
86
        return q
×
87
}
88

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

×
99
        q.Expression.AppendContextualModFunc(
×
100
                func(ctx context.Context, q *dialect.UpdateQuery) (context.Context, error) {
×
101
                        if !q.HasReturning() {
×
102
                                q.AppendReturning(t.returningCols)
×
103
                        }
×
104
                        return ctx, nil
×
105
                },
106
        )
107

108
        q.Apply(queryMods...)
×
109

×
110
        return q
×
111
}
112

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

×
123
        q.Expression.AppendContextualModFunc(
×
124
                func(ctx context.Context, q *dialect.DeleteQuery) (context.Context, error) {
×
125
                        if !q.HasReturning() {
×
126
                                q.AppendReturning(t.returningCols)
×
127
                        }
×
128
                        return ctx, nil
×
129
                },
130
        )
131

132
        q.Apply(queryMods...)
×
133

×
134
        return q
×
135
}
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