feat: use postgres to fetch and store user info

This commit is contained in:
nihonium 2025-11-27 09:42:05 +03:00
parent 79e8ece948
commit 6cbf0afb33
Signed by: nihonium
GPG key ID: 0251623741027CFC
9 changed files with 175 additions and 42 deletions

View file

@ -29,6 +29,25 @@ func (q *Queries) CreateImage(ctx context.Context, arg CreateImageParams) (Image
return i, err
}
const createNewUser = `-- name: CreateNewUser :one
INSERT
INTO users (passhash, nickname)
VALUES ($1, $2)
RETURNING id
`
type CreateNewUserParams struct {
Passhash string `json:"passhash"`
Nickname string `json:"nickname"`
}
func (q *Queries) CreateNewUser(ctx context.Context, arg CreateNewUserParams) (int64, error) {
row := q.db.QueryRow(ctx, createNewUser, arg.Passhash, arg.Nickname)
var id int64
err := row.Scan(&id)
return id, err
}
const getImageByID = `-- name: GetImageByID :one
SELECT id, storage_type, image_path
FROM images
@ -268,6 +287,29 @@ func (q *Queries) GetUserByID(ctx context.Context, id int64) (GetUserByIDRow, er
return i, err
}
const getUserByNickname = `-- name: GetUserByNickname :one
SELECT id, avatar_id, passhash, mail, nickname, disp_name, user_desc, creation_date, last_login
FROM users
WHERE nickname = $1
`
func (q *Queries) GetUserByNickname(ctx context.Context, nickname string) (User, error) {
row := q.db.QueryRow(ctx, getUserByNickname, nickname)
var i User
err := row.Scan(
&i.ID,
&i.AvatarID,
&i.Passhash,
&i.Mail,
&i.Nickname,
&i.DispName,
&i.UserDesc,
&i.CreationDate,
&i.LastLogin,
)
return i, err
}
const insertStudio = `-- name: InsertStudio :one
INSERT INTO studios (studio_name, illust_id, studio_desc)
VALUES (