-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
60 lines (47 loc) · 1.03 KB
/
select.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package pgq
type SelectCmd struct {
Cmd
fromCls *buffer
selectCls *buffer
whereCls *buffer
sql *buffer
}
func Select() *SelectCmd {
return &SelectCmd{
fromCls: pool.Get().(*buffer),
selectCls: pool.Get().(*buffer),
whereCls: pool.Get().(*buffer),
}
}
func (c *SelectCmd) Distinct(expr string) {
}
func (c *SelectCmd) Select(expr string) *SelectCmd {
if c.selectCls.len() > 0 {
c.selectCls.writeSQL(",")
}
c.selectCls.writeSQL(expr)
return c
}
func (c *SelectCmd) From(fromItem string) *SelectCmd {
if c.selectCls.len() > 0 {
c.selectCls.writeSQL(",")
}
c.selectCls.writeSQL(fromItem)
return c
}
func (c *SelectCmd) Where(cond string) *SelectCmd {
if c.whereCls.len() > 0 {
c.whereCls.writeSQL(" AND " + cond)
} else {
c.whereCls.writeSQL("WHERE " + cond)
}
return c
}
func (c *SelectCmd) SQL() string {
c.sql.writeString("SELECT ").write(c.selectCls)
c.sql.writeString(" FROM ").write(c.fromCls)
if c.whereCls.len() > 0 {
c.sql.writeString(" WHERE ").write(c.whereCls)
}
return c.sql.string()
}