-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.go
54 lines (46 loc) · 1.3 KB
/
id.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
package user
import (
"database/sql"
_ "embed"
"github.com/allocamelus/allocamelus/internal/data"
)
var (
//go:embed sql/idByEmail.sql
qIDByEmail string
preIDByEmail *sql.Stmt
//go:embed sql/emailByID.sql
qEmailByID string
preEmailByID *sql.Stmt
//go:embed sql/userNameByID.sql
qUserNameByID string
preUserNameByID *sql.Stmt
//go:embed sql/idByUserName.sql
qIDByUserName string
preIDByUserName *sql.Stmt
)
func init() {
data.PrepareQueuer.Add(&preIDByEmail, qIDByEmail)
data.PrepareQueuer.Add(&preEmailByID, qEmailByID)
data.PrepareQueuer.Add(&preUserNameByID, qUserNameByID)
data.PrepareQueuer.Add(&preIDByUserName, qIDByUserName)
}
// GetIDByEmail get user id by email
func GetIDByEmail(email string) (userID int64, err error) {
err = preIDByEmail.QueryRow(email).Scan(&userID)
return
}
// GetEmailByID get email by user id
func GetEmailByID(userID int64) (email string, err error) {
err = preEmailByID.QueryRow(userID).Scan(&email)
return
}
// GetUserNameByID get userName by user id
func GetUserNameByID(userID int64) (userName string, err error) {
err = preUserNameByID.QueryRow(userID).Scan(&userName)
return
}
// GetIDByUserName get user id by username
func GetIDByUserName(username string) (userID int64, err error) {
err = preIDByUserName.QueryRow(username).Scan(&userID)
return
}