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

stephenafamo / bob / 19668632728

25 Nov 2025 11:54AM UTC coverage: 42.301%. Remained the same
19668632728

push

github

web-flow
Merge pull request #589 from stephenafamo/string-writer

Use io.StringWriter instead of io.Writer for efficiency

196 of 295 new or added lines in 67 files covered. (66.44%)

9 existing lines in 5 files now uncovered.

9750 of 23049 relevant lines covered (42.3%)

569.79 hits per line

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

73.33
/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 string, 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 string
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
        if f.name == "" {
10✔
39
                return nil, nil
×
40
        }
×
41

42
        w.WriteString(f.name)
10✔
43
        w.WriteString("(")
10✔
44

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

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

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

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

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

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

10✔
75
        return args, nil
10✔
76
}
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