140 lines
3.6 KiB
Go
140 lines
3.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const checkUserExistsByEmail = `-- name: CheckUserExistsByEmail :one
|
|
SELECT id FROM users WHERE user_mail = $1
|
|
`
|
|
|
|
func (q *Queries) CheckUserExistsByEmail(ctx context.Context, userMail string) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, checkUserExistsByEmail, userMail)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (id, user_name, user_mail, password) VALUES ($1, $2, $3, $4) RETURNING id
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
UserName string `json:"user_name"`
|
|
UserMail string `json:"user_mail"`
|
|
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,
|
|
arg.UserName,
|
|
arg.UserMail,
|
|
arg.Password,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
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
|
|
`
|
|
|
|
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
|
|
}
|