Skip to content

Commit

Permalink
[*] refactor: re-type Offset and Limit from struct to int
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-M-C committed Jan 20, 2021
1 parent 8fbae4f commit 836f19f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
8 changes: 2 additions & 6 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ func (d *DB) handleArgs(prototype interface{}, args []interface{}) (ret *_parsed
case Options:
ret.Opt = mergeOptions(prototype, arg.(Options))
case Limit:
ret.Limit = arg.(Limit).Limit
case *Limit:
ret.Limit = arg.(*Limit).Limit
ret.Limit = int(arg.(Limit))
case Offset:
ret.Offset = arg.(Offset).Offset
case *Offset:
ret.Offset = arg.(*Offset).Offset
ret.Offset = int(arg.(Offset))
case Cond:
cond := arg.(Cond)
c = cond.pack(ret.FieldMap)
Expand Down
4 changes: 2 additions & 2 deletions basic_curd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestQuery(t *testing.T) {
Condition("family_name", "<>", "Disney"),
Condition("die_time", "=", nil), // for MySQL NULL, should be "IS" or "IS NOT", but here er make some compatibility
Condition("birth_date", ">=", time.Date(1910, 1, 1, 0, 0, 0, 0, time.UTC)),
Offset{1}, Limit{2},
Offset(1), Limit(2),
Order{"id", "DESC"},
)
if err != nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestQuery(t *testing.T) {
},
Condition("first_name", "=", "Diane"),
Condition("family_name", "=", "Miller"),
Limit{1},
Limit(1),
)
if err != nil {
t.Errorf("Update failed: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion insert_on_duplicate_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestInsertManyOnDuplicateKeyUpdate(t *testing.T) {

_, err = db.InsertManyOnDuplicateKeyUpdate(
ins, map[string]interface{}{
"f_id": Raw("= f_id"),
"f_id": Raw("= VALUES(`f_id`)"),
},
)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions raw.go

This file was deleted.

1 change: 1 addition & 0 deletions transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package mysqlx
16 changes: 10 additions & 6 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,15 @@ type Options struct {
}

// Offset is for MySQL offset statement
type Offset struct {
Offset int
}
type Offset int

// Limit is for MySQL limit statement
type Limit struct {
Limit int
}
type Limit int

// Raw stores a raw MySQL query statement. In mysqlx operation, Raw type will added to sql query statement directly
// without any escaping.
//
// Currently only update fields supports Raw, like:
//
// map[string]interface{}{"id": mysqlx.Raw("= id")}
type Raw string

0 comments on commit 836f19f

Please sign in to comment.