153 lines
3.2 KiB
Go
153 lines
3.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.24.0
|
|
// source: user.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (
|
|
username, hashed_password, email
|
|
) VALUES (
|
|
$1, $2, $3
|
|
)
|
|
RETURNING id, username, hashed_password, email, created_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `json:"username"`
|
|
HashedPassword string `json:"hashed_password"`
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, createUser, arg.Username, arg.HashedPassword, arg.Email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.HashedPassword,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteUser = `-- name: DeleteUser :exec
|
|
DELETE FROM users
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteUser, id)
|
|
return err
|
|
}
|
|
|
|
const getUser = `-- name: GetUser :one
|
|
SELECT id, username, hashed_password, email, created_at FROM users
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetUser(ctx context.Context, id string) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUser, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.HashedPassword,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByName = `-- name: GetUserByName :one
|
|
SELECT id, username, hashed_password, email, created_at FROM users
|
|
WHERE username = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetUserByName(ctx context.Context, username string) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByName, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.HashedPassword,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listUsers = `-- name: ListUsers :many
|
|
SELECT id, username, hashed_password, email, created_at FROM users
|
|
ORDER BY id
|
|
LIMIT $1
|
|
OFFSET $2
|
|
`
|
|
|
|
type ListUsersParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]User, error) {
|
|
rows, err := q.db.QueryContext(ctx, listUsers, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []User{}
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.HashedPassword,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :one
|
|
UPDATE users
|
|
SET hashed_password = $2,
|
|
email = $3
|
|
WHERE id = $1
|
|
RETURNING id, username, hashed_password, email, created_at
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
ID string `json:"id"`
|
|
HashedPassword string `json:"hashed_password"`
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, updateUser, arg.ID, arg.HashedPassword, arg.Email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.HashedPassword,
|
|
&i.Email,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|