Skip to content

Commit 380856f

Browse files
committed
Simplifying squirrel interface.
1 parent e1c3903 commit 380856f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+724
-2390
lines changed

.gitignore

-1
This file was deleted.

.travis.yml

-30
This file was deleted.

README.md

-142
This file was deleted.

case.go

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package squirrel
1+
package pgq
22

33
import (
44
"bytes"
@@ -11,23 +11,23 @@ func init() {
1111
builder.Register(CaseBuilder{}, caseData{})
1212
}
1313

14-
// sqlizerBuffer is a helper that allows to write many Sqlizers one by one
15-
// without constant checks for errors that may come from Sqlizer
14+
// sqlizerBuffer is a helper that allows to write many SQLizers one by one
15+
// without constant checks for errors that may come from SQLizer
1616
type sqlizerBuffer struct {
1717
bytes.Buffer
18-
args []interface{}
18+
args []any
1919
err error
2020
}
2121

22-
// WriteSql converts Sqlizer to SQL strings and writes it to buffer
23-
func (b *sqlizerBuffer) WriteSql(item Sqlizer) {
22+
// WriteSql converts SQLizer to SQL strings and writes it to buffer
23+
func (b *sqlizerBuffer) WriteSql(item SQLizer) {
2424
if b.err != nil {
2525
return
2626
}
2727

2828
var str string
29-
var args []interface{}
30-
str, args, b.err = nestedToSql(item)
29+
var args []any
30+
str, args, b.err = nestedSQL(item)
3131

3232
if b.err != nil {
3333
return
@@ -38,29 +38,29 @@ func (b *sqlizerBuffer) WriteSql(item Sqlizer) {
3838
b.args = append(b.args, args...)
3939
}
4040

41-
func (b *sqlizerBuffer) ToSql() (string, []interface{}, error) {
41+
func (b *sqlizerBuffer) SQL() (string, []any, error) {
4242
return b.String(), b.args, b.err
4343
}
4444

4545
// whenPart is a helper structure to describe SQLs "WHEN ... THEN ..." expression
4646
type whenPart struct {
47-
when Sqlizer
48-
then Sqlizer
47+
when SQLizer
48+
then SQLizer
4949
}
5050

51-
func newWhenPart(when interface{}, then interface{}) whenPart {
51+
func newWhenPart(when any, then any) whenPart {
5252
return whenPart{newPart(when), newPart(then)}
5353
}
5454

5555
// caseData holds all the data required to build a CASE SQL construct
5656
type caseData struct {
57-
What Sqlizer
57+
What SQLizer
5858
WhenParts []whenPart
59-
Else Sqlizer
59+
Else SQLizer
6060
}
6161

62-
// ToSql implements Sqlizer
63-
func (d *caseData) ToSql() (sqlStr string, args []interface{}, err error) {
62+
// SQL implements SQLizer
63+
func (d *caseData) SQL() (sqlStr string, args []any, err error) {
6464
if len(d.WhenParts) == 0 {
6565
err = errors.New("case expression must contain at lease one WHEN clause")
6666

@@ -88,41 +88,41 @@ func (d *caseData) ToSql() (sqlStr string, args []interface{}, err error) {
8888

8989
sql.WriteString("END")
9090

91-
return sql.ToSql()
91+
return sql.SQL()
9292
}
9393

9494
// CaseBuilder builds SQL CASE construct which could be used as parts of queries.
9595
type CaseBuilder builder.Builder
9696

97-
// ToSql builds the query into a SQL string and bound args.
98-
func (b CaseBuilder) ToSql() (string, []interface{}, error) {
97+
// SQL builds the query into a SQL string and bound args.
98+
func (b CaseBuilder) SQL() (string, []any, error) {
9999
data := builder.GetStruct(b).(caseData)
100-
return data.ToSql()
100+
return data.SQL()
101101
}
102102

103103
// MustSql builds the query into a SQL string and bound args.
104104
// It panics if there are any errors.
105-
func (b CaseBuilder) MustSql() (string, []interface{}) {
106-
sql, args, err := b.ToSql()
105+
func (b CaseBuilder) MustSQL() (string, []any) {
106+
sql, args, err := b.SQL()
107107
if err != nil {
108108
panic(err)
109109
}
110110
return sql, args
111111
}
112112

113113
// what sets optional value for CASE construct "CASE [value] ..."
114-
func (b CaseBuilder) what(expr interface{}) CaseBuilder {
114+
func (b CaseBuilder) what(expr any) CaseBuilder {
115115
return builder.Set(b, "What", newPart(expr)).(CaseBuilder)
116116
}
117117

118118
// When adds "WHEN ... THEN ..." part to CASE construct
119-
func (b CaseBuilder) When(when interface{}, then interface{}) CaseBuilder {
119+
func (b CaseBuilder) When(when any, then any) CaseBuilder {
120120
// TODO: performance hint: replace slice of WhenPart with just slice of parts
121121
// where even indices of the slice belong to "when"s and odd indices belong to "then"s
122122
return builder.Append(b, "WhenParts", newWhenPart(when, then)).(CaseBuilder)
123123
}
124124

125125
// What sets optional "ELSE ..." part for CASE construct
126-
func (b CaseBuilder) Else(expr interface{}) CaseBuilder {
126+
func (b CaseBuilder) Else(expr any) CaseBuilder {
127127
return builder.Set(b, "Else", newPart(expr)).(CaseBuilder)
128128
}

0 commit comments

Comments
 (0)