Skip to content

Commit

Permalink
Like to ddl pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Dec 28, 2021
1 parent f98958f commit 7d8e8bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ddl/arithsymbol/arithsymbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ const (
// Not e.g. is not null
Not ArithSymbol = "is not"
// In contained by a slice
In ArithSymbol = "in"
In ArithSymbol = "in"
Like ArithSymbol = "like"
)
12 changes: 11 additions & 1 deletion ddl/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ func (c Criteria) In(val interface{}) Criteria {
return c
}

// Like set like operator and column value, val should be a slice type value
func (c Criteria) Like(val interface{}) Criteria {
c.val = val
c.asym = arithsymbol.Like
return c
}

// And concat another sql expression builder with And
func (c Criteria) And(cri Base) Where {
w := Where{
Expand Down Expand Up @@ -311,7 +318,10 @@ type PageRet struct {

// NewPageRet new a PageRet
func NewPageRet(page Page) PageRet {
pageNo := page.Offset/page.Size + 1
pageNo := 1
if page.Size > 0 {
pageNo = page.Offset/page.Size + 1
}
return PageRet{
PageNo: pageNo,
PageSize: page.Size,
Expand Down
4 changes: 4 additions & 0 deletions ddl/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func ExampleCriteria() {
And(C().Col("cc.stat_type").Eq(2)).Append(String("for update"))
fmt.Println(where.Sql())

where = C().Col("cc.name").Like("%ba%")
fmt.Println(where.Sql())

// Output:
//((`name` = ? or `school` = ?) and `age` = ?) [wubin havard 18]
//((`name` = ? or `school` = ?) and `delete_at` is not null) [wubin havard]
Expand All @@ -95,4 +98,5 @@ func ExampleCriteria() {
//(`project_id` = ? and `delete_at` is null) for update [1]
//(cc.`project_id` = ? and cc.`delete_at` is null) for update [1]
//(((cc.`survey_id` = ? and cc.`year` = ?) and cc.`month` = ?) and cc.`stat_type` = ?) for update [abc 2021 10 2]
//cc.`name` like ? [%ba%]
}

0 comments on commit 7d8e8bb

Please sign in to comment.