Skip to content

Commit

Permalink
Add const od Direction: NULL (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Feb 1, 2024
1 parent 058635a commit 76b273d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions builder_x.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (x *BuilderX) Build() *Built {
Aggs: x.aggs,
Havings: x.havings,
GroupBys: x.groupBys,
Last: x.last,
OrFromSql: x.orFromSql,
Fxs: x.sxs,
Svs: x.svs,
Expand Down
7 changes: 6 additions & 1 deletion sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,6 +19,7 @@ package sqlxb
const (
asc = "ASC"
desc = "DESC"
nul = "NULL"
)

type Sort struct {
Expand All @@ -35,3 +36,7 @@ func ASC() string {
func DESC() string {
return desc
}

func NULL() string {
return nul
}
16 changes: 12 additions & 4 deletions to_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ type Built struct {
Havings []Bb
GroupBys []string
Aggs []Bb

OrFromSql string
Fxs []*FromX
Svs []interface{}
Last string
OrFromSql string
Fxs []*FromX
Svs []interface{}

PageCondition *PageCondition
}
Expand Down Expand Up @@ -244,6 +244,13 @@ func (built *Built) toPageSql(bp *strings.Builder) {
}
}

func (built *Built) toLastSql(bp *strings.Builder) {
if built.Last != "" {
bp.WriteString(SPACE)
bp.WriteString(built.Last)
}
}

func (built *Built) isOr(bb Bb) bool {
return bb.op == OR
}
Expand Down Expand Up @@ -327,6 +334,7 @@ func (built *Built) sqlData(vs *[]interface{}, km map[string]string) (string, ma
built.toHavingSql(vs, &sb)
built.toSortSql(&sb)
built.toPageSql(&sb)
built.toLastSql(&sb)
dataSql := sb.String()
return dataSql, km
}
Expand Down

0 comments on commit 76b273d

Please sign in to comment.