Skip to content

Commit

Permalink
Add X() to new builder (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Jan 1, 2024
1 parent a4a9535 commit bcfbae2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func main() {
sb.Select("id","type").From("t_pet").Gt("id", 10000) //....
}

builder := Of(nil).
builder := X().
Select("p.id","p.weight").
FromX(func(fb *FromBuilder) {
fb.
Expand Down
11 changes: 8 additions & 3 deletions builder_x.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ type BuilderX struct {
}

func Of(tableNameOrPo interface{}) *BuilderX {
x := new(BuilderX)
x.bbs = []Bb{}
x.sxs = []*FromX{}
x := X()
if tableNameOrPo != nil {
switch tableNameOrPo.(type) {
case string:
Expand All @@ -52,6 +50,13 @@ func Of(tableNameOrPo interface{}) *BuilderX {
return x
}

func X() *BuilderX {
x := new(BuilderX)
x.bbs = []Bb{}
x.sxs = []*FromX{}
return x
}

func (x *BuilderX) FromX(fromX func(fb *FromBuilder)) *BuilderX {

if len(x.sxs) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cond_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (cb *CondBuilder) NonNull(key string) *CondBuilder {

func (cb *CondBuilder) X(k string, vs ...interface{}) *CondBuilder {
bb := Bb{
op: X,
op: XX,
key: k,
value: vs,
}
Expand Down
2 changes: 1 addition & 1 deletion oper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package sqlxb

const (
X = ""
XX = ""
AGG = ""
SUB = "SUB"
AND = "AND"
Expand Down
2 changes: 1 addition & 1 deletion to_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (built *Built) toFromSql(vs *[]interface{}, bp *strings.Builder) {
func (built *Built) toBb(bb Bb, bp *strings.Builder, vs *[]interface{}) {
op := bb.op
switch op {
case X:
case XX:
bp.WriteString(bb.key)
if vs != nil && bb.value != nil {
arr := bb.value.([]interface{})
Expand Down

0 comments on commit bcfbae2

Please sign in to comment.