regenerate sqlc
This commit is contained in:
+82
-1
@@ -33,6 +33,7 @@ type CreateUserParams struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// users.sql
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.ID,
|
||||
@@ -45,14 +46,94 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (pgtype.
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, user_name, user_mail, created_at FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
type GetUserByIDRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserMail string `json:"user_mail"`
|
||||
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, id)
|
||||
var i GetUserByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserName,
|
||||
&i.UserMail,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUsernameByID = `-- name: GetUsernameByID :one
|
||||
SELECT user_name FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
// users.sql
|
||||
func (q *Queries) GetUsernameByID(ctx context.Context, id pgtype.UUID) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getUsernameByID, id)
|
||||
var user_name string
|
||||
err := row.Scan(&user_name)
|
||||
return user_name, err
|
||||
}
|
||||
|
||||
const loginUser = `-- name: LoginUser :one
|
||||
SELECT id, user_name, user_mail FROM users WHERE user_mail = $1 AND password = $2
|
||||
`
|
||||
|
||||
type LoginUserParams struct {
|
||||
UserMail string `json:"user_mail"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type LoginUserRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserMail string `json:"user_mail"`
|
||||
}
|
||||
|
||||
func (q *Queries) LoginUser(ctx context.Context, arg LoginUserParams) (LoginUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, loginUser, arg.UserMail, arg.Password)
|
||||
var i LoginUserRow
|
||||
err := row.Scan(&i.ID, &i.UserName, &i.UserMail)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUser = `-- name: UpdateUser :exec
|
||||
UPDATE users SET user_name = $2, user_mail = $3, password = $4 WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserName string `json:"user_name"`
|
||||
UserMail string `json:"user_mail"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
|
||||
_, err := q.db.Exec(ctx, updateUser,
|
||||
arg.ID,
|
||||
arg.UserName,
|
||||
arg.UserMail,
|
||||
arg.Password,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserSession = `-- name: UpdateUserSession :exec
|
||||
UPDATE users SET session_token = $2, session_expiry = $3 WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdateUserSessionParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
SessionToken pgtype.Text `json:"session_token"`
|
||||
SessionExpiry pgtype.Timestamp `json:"session_expiry"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserSession(ctx context.Context, arg UpdateUserSessionParams) error {
|
||||
_, err := q.db.Exec(ctx, updateUserSession, arg.ID, arg.SessionToken, arg.SessionExpiry)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user