-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (60 loc) · 1.48 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"log"
"strings"
"time"
_ "github.com/go-sql-driver/mysql"
"github.com/si3nloong/sqlike/sql/expr"
sqlstmt "github.com/si3nloong/sqlike/sql/stmt"
"github.com/si3nloong/sqlike/sqlike"
"github.com/si3nloong/sqlike/sqlike/actions"
"github.com/si3nloong/sqlike/sqlike/options"
)
type User struct {
ID string `gorm:"column:ID" xorm:"ID"`
Name string `gorm:"column:Name" xorm:"Name"`
Age int `gorm:"column:Age" xorm:"Age"`
Status string `gorm:"column:Status" xorm:"Status"`
CreatedAt time.Time `gorm:"column:CreatedAt" xorm:"CreatedAt"`
}
type Logger struct {
}
func (l Logger) Debug(stmt *sqlstmt.Statement) {
// log.Printf("%v", stmt)
log.Printf("%+v", stmt)
}
func main() {
query := "INSERT INTO `users` (`ID`, `Name`, `Age`, `Status`, `CreatedAt`) VALUES " + strings.Repeat(",(?,?,?,?,?)", 25)[1:] + ";"
log.Println(query)
ctx := context.Background()
client := sqlike.MustConnect(
ctx,
"mysql",
options.Connect().
SetUsername("root").
SetPassword("abcd1234").
SetHost("localhost").
SetPort("3306"),
)
client.SetPrimaryKey("ID")
client.SetLogger(&Logger{})
table := client.Database("sqlike").Table("users")
datas := []User{}
result, err := table.Paginate(
ctx,
actions.Paginate().
OrderBy(
expr.Desc("CreatedAt"),
),
options.Paginate().
SetDebug(true),
)
if err != nil {
panic(err)
}
result.NextCursor(ctx, "123")
result.All(&datas)
log.Println(result)
log.Println(err)
}