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

stephenafamo / bob / 18692828507

21 Oct 2025 05:48PM UTC coverage: 42.301%. Remained the same
18692828507

Pull #589

github

stephenafamo
Use io.StringWriter instead of io.Writer for efficiency
Pull Request #589: 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.81 hits per line

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

73.33
/dialect/sqlite/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 {
8✔
13
        f := &Function{name: name, args: args}
8✔
14
        f.Chain = expr.Chain[Expression, Expression]{Base: f}
8✔
15

8✔
16
        return f
8✔
17
}
8✔
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) {
8✔
38
        if f.name == "" {
8✔
39
                return nil, nil
×
40
        }
×
41

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

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

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

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

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

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

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

8✔
75
        return args, nil
8✔
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