-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.go
41 lines (34 loc) · 1010 Bytes
/
sql.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
package dao
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
"github.com/topcoder520/gfsr/fileserver/logs"
"github.com/topcoder520/gfsr/fileserver/model"
"github.com/topcoder520/gossql"
)
var commonDao *gossql.GoSql
func init() {
godb, err := sql.Open("sqlite3", "./fileserver.db")
if err != nil {
logs.Println(err)
return
}
commonDao = gossql.New(godb)
}
func GetUserByUsername(username string) *model.LoginUser {
loginUser := &model.LoginUser{}
commonDao.Query("select * from LoginUser where username=?", username).Unique(loginUser)
return loginUser
}
func ExistUser(username, password string) bool {
count := 0
err := commonDao.Query("select count(1) from LoginUser where username=? and password=?", username, password).Count(&count)
if err != nil {
logs.Error(err)
return false
}
return count > 0
}
func AddLoginLog(loginLog *model.LoginLog) {
commonDao.Insert("insert into LoginLog(LoginUserId,CreateTime) values(?,?)", loginLog.LoginUserId, loginLog.CreateTime)
}