get by id
This commit is contained in:
parent
ebd3dcea87
commit
b062c4aea1
42
main.go
42
main.go
|
@ -132,6 +132,48 @@ func Get(username string) (*UserData, bool) {
|
||||||
return u, ok
|
return u, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetById(id int64) (*UserData, bool) {
|
||||||
|
u := NewUser()
|
||||||
|
q := fmt.Sprintf("select username, password, id from %s_users where id=?", c.TablePrefix)
|
||||||
|
err := c.db.Get(u, q, id)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
log.Printf("scsusers.Get: %s", err.Error())
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
ok := u.LoadMeta()
|
||||||
|
return u, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUsersByMeta(key string, value string) []string {
|
||||||
|
var u []string
|
||||||
|
var userids []int64
|
||||||
|
q := fmt.Sprintf("select user from %s_meta where meta_key=? AND meta_value=?", c.TablePrefix)
|
||||||
|
err := c.db.Select(&userids, q, key, value)
|
||||||
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
log.Printf("scsusers.getusersByMeta: %s", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(userids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
q = fmt.Sprintf("select username from %s_users where id IN (?)", c.TablePrefix)
|
||||||
|
query, args, err := sqlx.In(q, userids)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("scsusers.getusersbymeta: %s", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query = c.db.Rebind(query)
|
||||||
|
err = c.db.Select(&u, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("scsusers.getusersbymeta: %s", err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserid(username string) int64 {
|
func GetUserid(username string) int64 {
|
||||||
var i int64
|
var i int64
|
||||||
username = strings.ToLower(username)
|
username = strings.ToLower(username)
|
||||||
|
|
Loading…
Reference in New Issue