Skip to content

Commit 2c0ae13

Browse files
committed
golint fixed
1 parent cd42e83 commit 2c0ae13

21 files changed

+188
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SQL builder
22

3-
Package builder is a simple and powerful sql builder for Go.
3+
Package builder is a lightweight and fast SQL builder for Go and XORM.
44

55
Make sure you have installed Go 1.1+ and then:
66

builder.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
type optype byte
@@ -16,6 +20,7 @@ type join struct {
1620
joinCond Cond
1721
}
1822

23+
// Builder describes a SQL statement
1924
type Builder struct {
2025
optype
2126
tableName string
@@ -26,41 +31,49 @@ type Builder struct {
2631
updates []Eq
2732
}
2833

34+
// Select creates a select Builder
2935
func Select(cols ...string) *Builder {
3036
builder := &Builder{cond: NewCond()}
3137
return builder.Select(cols...)
3238
}
3339

40+
// Insert creates an insert Builder
3441
func Insert(eq Eq) *Builder {
3542
builder := &Builder{cond: NewCond()}
3643
return builder.Insert(eq)
3744
}
3845

46+
// Update creates an update Builder
3947
func Update(updates ...Eq) *Builder {
4048
builder := &Builder{cond: NewCond()}
4149
return builder.Update(updates...)
4250
}
4351

52+
// Delete creates a delete Builder
4453
func Delete(conds ...Cond) *Builder {
4554
builder := &Builder{cond: NewCond()}
4655
return builder.Delete(conds...)
4756
}
4857

58+
// Where sets where SQL
4959
func (b *Builder) Where(cond Cond) *Builder {
5060
b.cond = b.cond.And(cond)
5161
return b
5262
}
5363

64+
// From sets the table name
5465
func (b *Builder) From(tableName string) *Builder {
5566
b.tableName = tableName
5667
return b
5768
}
5869

70+
// Into sets insert table name
5971
func (b *Builder) Into(tableName string) *Builder {
6072
b.tableName = tableName
6173
return b
6274
}
6375

76+
// Join sets join table and contions
6477
func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder {
6578
switch joinCond.(type) {
6679
case Cond:
@@ -72,60 +85,72 @@ func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builde
7285
return b
7386
}
7487

88+
// InnerJoin sets inner join
7589
func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder {
7690
return b.Join("INNER", joinTable, joinCond)
7791
}
7892

93+
// LeftJoin sets left join SQL
7994
func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder {
8095
return b.Join("LEFT", joinTable, joinCond)
8196
}
8297

98+
// RightJoin sets right join SQL
8399
func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder {
84100
return b.Join("RIGHT", joinTable, joinCond)
85101
}
86102

103+
// CrossJoin sets cross join SQL
87104
func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder {
88105
return b.Join("CROSS", joinTable, joinCond)
89106
}
90107

108+
// FullJoin sets full join SQL
91109
func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder {
92110
return b.Join("FULL", joinTable, joinCond)
93111
}
94112

113+
// Select sets select SQL
95114
func (b *Builder) Select(cols ...string) *Builder {
96115
b.selects = cols
97116
b.optype = selectType
98117
return b
99118
}
100119

120+
// And sets AND condition
101121
func (b *Builder) And(cond Cond) *Builder {
102122
b.cond = And(b.cond, cond)
103123
return b
104124
}
105125

126+
// Or sets OR condition
106127
func (b *Builder) Or(cond Cond) *Builder {
107128
b.cond = Or(b.cond, cond)
108129
return b
109130
}
110131

132+
// Insert sets insert SQL
111133
func (b *Builder) Insert(eq Eq) *Builder {
112134
b.inserts = eq
113135
b.optype = insertType
114136
return b
115137
}
116138

139+
// Update sets update SQL
117140
func (b *Builder) Update(updates ...Eq) *Builder {
118141
b.updates = updates
119142
b.optype = updateType
120143
return b
121144
}
122145

146+
// Delete sets delete SQL
123147
func (b *Builder) Delete(conds ...Cond) *Builder {
124148
b.cond = b.cond.And(conds...)
125149
b.optype = deleteType
126150
return b
127151
}
128152

153+
// WriteTo implements Writer interface
129154
func (b *Builder) WriteTo(w Writer) error {
130155
switch b.optype {
131156
case condType:

builder_delete.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (

builder_insert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (

builder_select.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (

builder_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (

builder_update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (

cond.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import (
48
"bytes"
59
"io"
610
)
711

12+
// Writer defines the interface
813
type Writer interface {
914
io.Writer
1015
Append(...interface{})
1116
}
1217

13-
type stringWriter struct {
18+
var _ Writer = NewWriter()
19+
20+
// BytesWriter implments Writer and save SQL in bytes.Buffer
21+
type BytesWriter struct {
1422
writer *bytes.Buffer
1523
buffer []byte
1624
args []interface{}
1725
}
1826

19-
func NewWriter() *stringWriter {
20-
w := &stringWriter{}
27+
// NewWriter creates a new string writer
28+
func NewWriter() *BytesWriter {
29+
w := &BytesWriter{}
2130
w.writer = bytes.NewBuffer(w.buffer)
2231
return w
2332
}
2433

25-
func (s *stringWriter) Write(buf []byte) (int, error) {
34+
// Write writes data to Writer
35+
func (s *BytesWriter) Write(buf []byte) (int, error) {
2636
return s.writer.Write(buf)
2737
}
2838

29-
func (s *stringWriter) Append(args ...interface{}) {
39+
// Append appends args to Writer
40+
func (s *BytesWriter) Append(args ...interface{}) {
3041
s.args = append(s.args, args...)
3142
}
3243

44+
// Cond defines an interface
3345
type Cond interface {
3446
WriteTo(Writer) error
3547
And(...Cond) Cond
@@ -41,6 +53,7 @@ type condEmpty struct{}
4153

4254
var _ Cond = condEmpty{}
4355

56+
// NewCond creates an empty condition
4457
func NewCond() Cond {
4558
return condEmpty{}
4659
}

cond_and.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import "fmt"
@@ -6,6 +10,7 @@ type condAnd []Cond
610

711
var _ Cond = condAnd{}
812

13+
// And generates AND conditions
914
func And(conds ...Cond) Cond {
1015
var result = make(condAnd, 0, len(conds))
1116
for _, cond := range conds {

cond_between.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
// Copyright 2016 The Xorm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
15
package builder
26

37
import "fmt"
48

5-
// Between
9+
// Between implmentes between condition
610
type Between struct {
711
Col string
812
LessVal interface{}
@@ -11,6 +15,7 @@ type Between struct {
1115

1216
var _ Cond = Between{}
1317

18+
// WriteTo write data to Writer
1419
func (between Between) WriteTo(w Writer) error {
1520
if _, err := fmt.Fprintf(w, "%s BETWEEN ? AND ?", between.Col); err != nil {
1621
return err
@@ -19,14 +24,17 @@ func (between Between) WriteTo(w Writer) error {
1924
return nil
2025
}
2126

27+
// And implments And with other conditions
2228
func (between Between) And(conds ...Cond) Cond {
2329
return And(between, And(conds...))
2430
}
2531

32+
// Or implments Or with other conditions
2633
func (between Between) Or(conds ...Cond) Cond {
2734
return Or(between, Or(conds...))
2835
}
2936

37+
// IsValid tests if the condition is valid
3038
func (between Between) IsValid() bool {
3139
return len(between.Col) > 0
3240
}

0 commit comments

Comments
 (0)