-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
43 lines (33 loc) · 917 Bytes
/
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
package models
import (
"github.com/macococo/go-gamereviews/utils"
)
type User struct {
Id int
Name string
Type int
Model
}
type UserManager struct {
}
func (this *UserManager) TableName() string {
return "t_user"
}
func (this *UserManager) AddTable() {
DbMap.AddTableWithName(User{}, this.TableName()).SetKeys(true, "Id")
}
func (this *UserManager) Count(t int) int64 {
count, err := DbMap.SelectInt("SELECT count(*) FROM "+this.TableName()+" WHERE type = ?", t)
utils.HandleError(err)
return count
}
func (this *UserManager) Find(t int, pagination *Pagination) []*User {
var users []*User
_, err := DbMap.Select(&users, "SELECT * FROM "+this.TableName()+" WHERE type = ? LIMIT ?, ?", t, (pagination.Page-1)*pagination.Length, pagination.Length)
utils.HandleError(err)
return users
}
func (this *UserManager) Create(user *User) *User {
utils.HandleError(DbMap.Insert(user))
return user
}