diff options
Diffstat (limited to 'backend/db')
| -rw-r--r-- | backend/db/queries/users.sql | 14 | ||||
| -rw-r--r-- | backend/db/users.sql.go | 69 |
2 files changed, 83 insertions, 0 deletions
diff --git a/backend/db/queries/users.sql b/backend/db/queries/users.sql new file mode 100644 index 0000000..99515d5 --- /dev/null +++ b/backend/db/queries/users.sql @@ -0,0 +1,14 @@ +-- name: CreateUser :one +INSERT INTO users (username, password_hash) +VALUES (?, ?) +RETURNING *; + +-- name: GetUserByUsername :one +SELECT id, username, password_hash, created_at +FROM users +WHERE username = ?; + +-- name: GetUserByID :one +SELECT id, username, password_hash, created_at +FROM users +WHERE id = ?; diff --git a/backend/db/users.sql.go b/backend/db/users.sql.go new file mode 100644 index 0000000..7255eba --- /dev/null +++ b/backend/db/users.sql.go @@ -0,0 +1,69 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 +// source: users.sql + +package db + +import ( + "context" +) + +const createUser = `-- name: CreateUser :one +INSERT INTO users (username, password_hash) +VALUES (?, ?) +RETURNING id, username, password_hash, created_at +` + +type CreateUserParams struct { + Username string + PasswordHash string +} + +func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { + row := q.db.QueryRowContext(ctx, createUser, arg.Username, arg.PasswordHash) + var i User + err := row.Scan( + &i.ID, + &i.Username, + &i.PasswordHash, + &i.CreatedAt, + ) + return i, err +} + +const getUserByID = `-- name: GetUserByID :one +SELECT id, username, password_hash, created_at +FROM users +WHERE id = ? +` + +func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) { + row := q.db.QueryRowContext(ctx, getUserByID, id) + var i User + err := row.Scan( + &i.ID, + &i.Username, + &i.PasswordHash, + &i.CreatedAt, + ) + return i, err +} + +const getUserByUsername = `-- name: GetUserByUsername :one +SELECT id, username, password_hash, created_at +FROM users +WHERE username = ? +` + +func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) { + row := q.db.QueryRowContext(ctx, getUserByUsername, username) + var i User + err := row.Scan( + &i.ID, + &i.Username, + &i.PasswordHash, + &i.CreatedAt, + ) + return i, err +} |
