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

stephenafamo / bob / 14991965966

13 May 2025 08:31AM UTC coverage: 36.665% (-0.2%) from 36.87%
14991965966

Pull #413

github

stephenafamo
More query refactoring
Pull Request #413: More query refactoring

64 of 327 new or added lines in 36 files covered. (19.57%)

6 existing lines in 2 files now uncovered.

6507 of 17747 relevant lines covered (36.67%)

212.33 hits per line

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

27.88
/dialect/sqlite/dialect/mods.go
1
package dialect
2

3
import (
4
        "github.com/stephenafamo/bob"
5
        "github.com/stephenafamo/bob/clause"
6
        "github.com/stephenafamo/bob/expr"
7
        "github.com/stephenafamo/bob/mods"
8
)
9

10
func With[Q interface{ AppendCTE(bob.Expression) }](name string, columns ...string) CTEChain[Q] {
×
11
        return CTEChain[Q](func() clause.CTE {
×
12
                return clause.CTE{
×
13
                        Name:    name,
×
14
                        Columns: columns,
×
15
                }
×
16
        })
×
17
}
18

19
type CTEChain[Q interface{ AppendCTE(bob.Expression) }] func() clause.CTE
20

21
func (c CTEChain[Q]) Apply(q Q) {
×
22
        q.AppendCTE(c())
×
23
}
×
24

25
func (c CTEChain[Q]) As(q bob.Query) CTEChain[Q] {
×
26
        cte := c()
×
27
        cte.Query = q
×
28
        return CTEChain[Q](func() clause.CTE {
×
29
                return cte
×
30
        })
×
31
}
32

33
func (c CTEChain[Q]) NotMaterialized() CTEChain[Q] {
×
34
        b := false
×
35
        cte := c()
×
36
        cte.Materialized = &b
×
37
        return CTEChain[Q](func() clause.CTE {
×
38
                return cte
×
39
        })
×
40
}
41

42
func (c CTEChain[Q]) Materialized() CTEChain[Q] {
×
43
        b := true
×
44
        cte := c()
×
45
        cte.Materialized = &b
×
46
        return CTEChain[Q](func() clause.CTE {
×
47
                return cte
×
48
        })
×
49
}
50

51
func OrAbort[Q interface{ SetOr(string) }]() bob.Mod[Q] {
×
52
        return bob.ModFunc[Q](func(i Q) {
×
53
                i.SetOr("ABORT")
×
54
        })
×
55
}
56

57
func OrFail[Q interface{ SetOr(string) }]() bob.Mod[Q] {
×
58
        return bob.ModFunc[Q](func(i Q) {
×
59
                i.SetOr("FAIL")
×
60
        })
×
61
}
62

63
func OrIgnore[Q interface{ SetOr(string) }]() bob.Mod[Q] {
×
64
        return bob.ModFunc[Q](func(i Q) {
×
65
                i.SetOr("IGNORE")
×
66
        })
×
67
}
68

69
func OrReplace[Q interface{ SetOr(string) }]() bob.Mod[Q] {
2✔
70
        return bob.ModFunc[Q](func(i Q) {
4✔
71
                i.SetOr("REPLACE")
2✔
72
        })
2✔
73
}
74

75
func OrRollback[Q interface{ SetOr(string) }]() bob.Mod[Q] {
×
76
        return bob.ModFunc[Q](func(i Q) {
×
77
                i.SetOr("ROLLBACK")
×
78
        })
×
79
}
80

81
type fromable interface {
82
        SetTable(any)
83
        SetTableAlias(alias string, columns ...string)
84
        SetIndexedBy(*string)
85
}
86

87
func From[Q fromable](table any) FromChain[Q] {
30✔
88
        return FromChain[Q](func() clause.TableRef {
60✔
89
                return clause.TableRef{Expression: table}
30✔
90
        })
30✔
91
}
92

93
type FromChain[Q fromable] func() clause.TableRef
94

95
func (f FromChain[Q]) Apply(q Q) {
30✔
96
        from := f()
30✔
97

30✔
98
        q.SetTable(from.Expression)
30✔
99
        if from.Alias != "" {
36✔
100
                q.SetTableAlias(from.Alias, from.Columns...)
6✔
101
        }
6✔
102

103
        q.SetIndexedBy(from.IndexedBy)
30✔
104
}
105

106
func (f FromChain[Q]) As(alias string) FromChain[Q] {
6✔
107
        fr := f()
6✔
108
        fr.Alias = alias
6✔
109

6✔
110
        return FromChain[Q](func() clause.TableRef {
12✔
111
                return fr
6✔
112
        })
6✔
113
}
114

115
func (f FromChain[Q]) NotIndexed() bob.Mod[Q] {
×
116
        i := ""
×
117
        fr := f()
×
118
        fr.SetIndexedBy(&i)
×
119

×
NEW
120
        return FromChain[Q](func() clause.TableRef {
×
121
                return fr
×
122
        })
×
123
}
124

125
func (f FromChain[Q]) IndexedBy(indexName string) bob.Mod[Q] {
×
126
        fr := f()
×
127
        fr.SetIndexedBy(&indexName)
×
128

×
NEW
129
        return FromChain[Q](func() clause.TableRef {
×
130
                return fr
×
131
        })
×
132
}
133

134
type JoinChain[Q interface{ AppendJoin(clause.Join) }] func() clause.Join
135

136
func (j JoinChain[Q]) Apply(q Q) {
×
137
        q.AppendJoin(j())
×
138
}
×
139

140
func (f JoinChain[Q]) NotIndexed() bob.Mod[Q] {
×
141
        i := ""
×
142
        jo := f()
×
143
        jo.To.SetIndexedBy(&i)
×
144

×
145
        return JoinChain[Q](func() clause.Join {
×
146
                return jo
×
147
        })
×
148
}
149

150
func (f JoinChain[Q]) IndexedBy(indexName string) bob.Mod[Q] {
×
151
        jo := f()
×
152
        jo.To.SetIndexedBy(&indexName)
×
153

×
154
        return JoinChain[Q](func() clause.Join {
×
155
                return jo
×
156
        })
×
157
}
158

159
func (j JoinChain[Q]) As(alias string) JoinChain[Q] {
×
160
        jo := j()
×
161
        jo.To.Alias = alias
×
162

×
163
        return JoinChain[Q](func() clause.Join {
×
164
                return jo
×
165
        })
×
166
}
167

168
func (j JoinChain[Q]) Natural() bob.Mod[Q] {
×
169
        jo := j()
×
170
        jo.Natural = true
×
171

×
172
        return mods.Join[Q](jo)
×
173
}
×
174

175
func (j JoinChain[Q]) On(on ...bob.Expression) bob.Mod[Q] {
×
176
        jo := j()
×
177
        jo.On = append(jo.On, on...)
×
178

×
179
        return mods.Join[Q](jo)
×
180
}
×
181

182
func (j JoinChain[Q]) OnEQ(a, b bob.Expression) bob.Mod[Q] {
×
183
        jo := j()
×
184
        jo.On = append(jo.On, expr.X[Expression, Expression](a).EQ(b))
×
185

×
186
        return mods.Join[Q](jo)
×
187
}
×
188

189
func (j JoinChain[Q]) Using(using ...string) bob.Mod[Q] {
×
190
        jo := j()
×
191
        jo.Using = using
×
192

×
193
        return mods.Join[Q](jo)
×
194
}
×
195

196
type CrossJoinChain[Q Joinable] func() clause.Join
197

198
func (j CrossJoinChain[Q]) Apply(q Q) {
2✔
199
        q.AppendJoin(j())
2✔
200
}
2✔
201

202
func (j CrossJoinChain[Q]) As(alias string, columns ...string) bob.Mod[Q] {
2✔
203
        jo := j()
2✔
204
        jo.To.Alias = alias
2✔
205
        jo.To.Columns = columns
2✔
206

2✔
207
        return CrossJoinChain[Q](func() clause.Join {
4✔
208
                return jo
2✔
209
        })
2✔
210
}
211

212
type Joinable interface{ AppendJoin(clause.Join) }
213

214
func Join[Q Joinable](typ string, e any) JoinChain[Q] {
×
215
        return JoinChain[Q](func() clause.Join {
×
216
                return clause.Join{
×
217
                        Type: typ,
×
NEW
218
                        To:   clause.TableRef{Expression: e},
×
219
                }
×
220
        })
×
221
}
222

223
func InnerJoin[Q Joinable](e any) JoinChain[Q] {
×
224
        return Join[Q](clause.InnerJoin, e)
×
225
}
×
226

227
func LeftJoin[Q Joinable](e any) JoinChain[Q] {
×
228
        return Join[Q](clause.LeftJoin, e)
×
229
}
×
230

231
func RightJoin[Q Joinable](e any) JoinChain[Q] {
×
232
        return Join[Q](clause.RightJoin, e)
×
233
}
×
234

235
func FullJoin[Q Joinable](e any) JoinChain[Q] {
×
236
        return Join[Q](clause.FullJoin, e)
×
237
}
×
238

239
func CrossJoin[Q Joinable](e any) CrossJoinChain[Q] {
2✔
240
        return CrossJoinChain[Q](func() clause.Join {
4✔
241
                return clause.Join{
2✔
242
                        Type: clause.CrossJoin,
2✔
243
                        To:   clause.TableRef{Expression: e},
2✔
244
                }
2✔
245
        })
2✔
246
}
247

248
type OrderBy[Q interface{ AppendOrder(bob.Expression) }] func() clause.OrderDef
249

250
func (s OrderBy[Q]) Apply(q Q) {
4✔
251
        q.AppendOrder(s())
4✔
252
}
4✔
253

254
func (o OrderBy[Q]) Collate(collationName string) OrderBy[Q] {
2✔
255
        order := o()
2✔
256
        order.Collation = collationName
2✔
257

2✔
258
        return OrderBy[Q](func() clause.OrderDef {
4✔
259
                return order
2✔
260
        })
2✔
261
}
262

263
func (o OrderBy[Q]) Asc() OrderBy[Q] {
2✔
264
        order := o()
2✔
265
        order.Direction = "ASC"
2✔
266

2✔
267
        return OrderBy[Q](func() clause.OrderDef {
4✔
268
                return order
2✔
269
        })
2✔
270
}
271

272
func (o OrderBy[Q]) Desc() OrderBy[Q] {
×
273
        order := o()
×
274
        order.Direction = "DESC"
×
275

×
276
        return OrderBy[Q](func() clause.OrderDef {
×
277
                return order
×
278
        })
×
279
}
280

281
func (o OrderBy[Q]) NullsFirst() OrderBy[Q] {
×
282
        order := o()
×
283
        order.Nulls = "FIRST"
×
284

×
285
        return OrderBy[Q](func() clause.OrderDef {
×
286
                return order
×
287
        })
×
288
}
289

290
func (o OrderBy[Q]) NullsLast() OrderBy[Q] {
×
291
        order := o()
×
292
        order.Nulls = "LAST"
×
293

×
294
        return OrderBy[Q](func() clause.OrderDef {
×
295
                return order
×
296
        })
×
297
}
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