Skip to content

Commit

Permalink
Simplify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Mar 22, 2024
1 parent 382537b commit fa538cb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func ExampleBuilder_DebugBuild() {
b.Addf("MORE offset = %$", d)
b.Addf("MAYBE IN arr = %$", []int{1, 2, 3})

fmt.Printf("debug:\n%v", b.DebugBuild())
fmt.Println("debug:")
fmt.Println(b.DebugBuild())

// Output:
// debug:
Expand Down Expand Up @@ -283,27 +284,27 @@ func Example_queryWhere() {
"limit": 100.1,
}

var b builq.Builder
b.Addf("SELECT * FROM foo")
b.Addf("WHERE active IS TRUE")
q := builq.New()
q("SELECT * FROM foo")
q("WHERE active IS TRUE")

if name, ok := filter["name"]; ok {
b.Addf("AND name = %$", name)
q("AND name = %$", name)
}
if cat, ok := filter["category"]; ok {
b.Addf("AND category IN (%+$)", cat)
q("AND category IN (%+$)", cat)
}
if pat, ok := filter["pat"]; ok {
b.Addf("AND page LIKE '%s'", pat)
q("AND page LIKE '%s'", pat)
}
if prob, ok := filter["prob"]; ok {
b.Addf("AND prob < %s", prob)
q("AND prob < %s", prob)
}
if limit, ok := filter["limit"]; ok {
b.Addf("LIMIT %d;", limit)
q("LIMIT %d;", limit)
}

query, args, err := b.Build()
query, args, err := q.Build()
if err != nil {
panic(err)
}
Expand Down

0 comments on commit fa538cb

Please sign in to comment.