-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuser.go
104 lines (88 loc) · 3.16 KB
/
user.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package store
import (
"database/sql"
"time"
"github.com/omigo/light/example/model"
)
//go:generate light -log -timeout 30
var User IUser
type IUser interface {
// CREATE TABLE if NOT EXISTS #{name} (
// id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
// username VARCHAR(32) NOT NULL UNIQUE,
// Phone VARCHAR(32),
// address VARCHAR(256),
// _status TINYINT UNSIGNED,
// birth_day DATE,
// created TIMESTAMP default CURRENT_TIMESTAMP,
// updated TIMESTAMP default CURRENT_TIMESTAMP
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Create(name string) error
// insert ignore into users(`username`, phone, address, _status, birth_day, created, updated)
// values (${u.Username},?,?,?,?,CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
Insert(tx *sql.Tx, u *model.User) (a int64, b error)
// insert ignore into users(`username`, phone, address, _status, birth_day, created, updated)
// values (${u.Username},?,?,?,?,CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
Bulky(us []*model.User) (insertedRows int64, ignoreRows int64, err error)
// insert into users(username, phone, address, _status, birth_day, created, updated)
// values (?,?,?,?,?,CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
// on duplicate key update
// username=values(username), phone=values(phone), address=values(address),
// _status=values(_status), birth_day=values(birth_day), updated=CURRENT_TIMESTAMP
Upsert(u *model.User, tx *sql.Tx) (int64, error)
// replace into users(username, phone, address, _status, birth_day, created, updated)
// values (?,?,?,?,?,CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
Replace(u *model.User) (int64, error)
// UPDATE users
// SET [username=?,]
// [phone=?,]
// [address=?,]
// [_status=?,]
// [birth_day=?,]
// updated=CURRENT_TIMESTAMP
// WHERE id=?
Update(u *model.User) (int64, error)
// DELETE FROM users WHERE id=?
Delete(id uint64) (int64, error)
// select id, username, mobile, address, _status, birth_day, created, updated
// FROM users WHERE id=?
Get(id uint64) (ret *model.User, e error)
// select count(1)
// from users
// where birth_day < ?
Count(birthDay time.Time) (int64, error)
// select (select id from users where id=a.id) as id,
// `username`, phone as phone, address, _status, birth_day, created, updated
// from users a
// where id != -1 and username <> 'admin' and username like ?
// [
// and address = ?
// [and phone like ?]
// and created > ?
// [{(u.BirthDay != nil && !u.BirthDay.IsZero()) || u.Id > 1 }
// [and birth_day > ?]
// [and id > ?]
// ]
// ]
// and _status != ?
// [and updated > ?]
// and birth_day is not null
// order by updated desc
// limit ${offset}, ${size}
List(u *model.User, offset, size int) (us []*model.User, xxx error)
// select id, username, if(phone='', '0', phone) phone, address, _status, birth_day, created, updated
// from users
// where username like ?
// [
// and address = ?
// [and phone like ?]
// and created > ?
// ]
// and birth_day is not null
// and _status != ?
// [{ range } and _status in (#{ss})]
// [and updated > ?]
// order by updated desc
// limit ${offset}, ${size}
Page(u *model.User, ss []model.Status, offset int, size int) (int64, []*model.User, error)
}