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

stephenafamo / bob / 16945466045

13 Aug 2025 06:04PM UTC coverage: 41.426% (+0.1%) from 41.305%
16945466045

push

github

stephenafamo
Use correct default folder for `dbinfo` plugin

2 of 2 new or added lines in 2 files covered. (100.0%)

201 existing lines in 11 files now uncovered.

9438 of 22783 relevant lines covered (41.43%)

283.05 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
)
16

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

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

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

×
37
        return t
×
UNCOV
38
}
×
39

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

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

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

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

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

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

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

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

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

×
UNCOV
87
        return q
×
88
}
89

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

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

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

×
UNCOV
111
        return q
×
112
}
113

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

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

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

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