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

stephenafamo / bob / 26506256479

27 May 2026 10:40AM UTC coverage: 45.826% (+0.5%) from 45.366%
26506256479

Pull #697

github

Roman A. Grigorovich
refactor: improve SQL formatter error handling and clean up code
Pull Request #697: fix: quote SQL identifiers across dialects

125 of 177 new or added lines in 30 files covered. (70.62%)

5 existing lines in 5 files now uncovered.

11241 of 24530 relevant lines covered (45.83%)

664.14 hits per line

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

73.91
/dialect/mysql/dialect/function.go
1
package dialect
2

3
import (
4
        "context"
5
        "io"
6

7
        "github.com/stephenafamo/bob"
8
        "github.com/stephenafamo/bob/clause"
9
        "github.com/stephenafamo/bob/expr"
10
)
11

12
func NewFunction(name any, args ...any) *Function {
10✔
13
        f := &Function{name: name, args: args}
10✔
14
        f.Chain = expr.Chain[Expression, Expression]{Base: f}
10✔
15

10✔
16
        return f
10✔
17
}
10✔
18

19
type Function struct {
20
        name any
21
        args []any
22

23
        // Used in value functions. Supported by Sqlite and Postgres
24
        Distinct bool
25
        clause.OrderBy
26
        Filter []any
27
        w      *clause.Window
28

29
        // For chain methods
30
        expr.Chain[Expression, Expression]
31
}
32

33
func (f *Function) SetWindow(w clause.Window) {
2✔
34
        f.w = &w
2✔
35
}
2✔
36

37
func (f Function) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
10✔
38
        nameArgs, err := bob.Express(ctx, w, d, start, f.name)
10✔
39
        if err != nil {
10✔
NEW
40
                return nil, err
×
UNCOV
41
        }
×
42

43
        w.WriteString("(")
10✔
44
        start += len(nameArgs)
10✔
45

10✔
46
        if f.Distinct {
10✔
47
                w.WriteString("DISTINCT ")
×
48
        }
×
49

50
        args, err := bob.ExpressSlice(ctx, w, d, start, f.args, "", ", ", "")
10✔
51
        if err != nil {
10✔
52
                return nil, err
×
53
        }
×
54

55
        orderArgs, err := bob.ExpressIf(ctx, w, d, start+len(args), f.OrderBy,
10✔
56
                len(f.OrderBy.Expressions) > 0, " ", "")
10✔
57
        if err != nil {
10✔
58
                return nil, err
×
59
        }
×
60
        args = append(args, orderArgs...)
10✔
61

10✔
62
        w.WriteString(")")
10✔
63

10✔
64
        filterArgs, err := bob.ExpressSlice(ctx, w, d, start, f.Filter, " FILTER (WHERE ", " AND ", ")")
10✔
65
        if err != nil {
10✔
66
                return nil, err
×
67
        }
×
68
        args = append(args, filterArgs...)
10✔
69

10✔
70
        winargs, err := bob.ExpressIf(ctx, w, d, start+len(args), f.w, f.w != nil, "OVER (", ")")
10✔
71
        if err != nil {
10✔
72
                return nil, err
×
73
        }
×
74
        args = append(args, winargs...)
10✔
75

10✔
76
        return append(nameArgs, args...), nil
10✔
77
}
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