212 lines
4.7 KiB
Go
212 lines
4.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: users.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const archiveUser = `-- name: ArchiveUser :exec
|
|
UPDATE users
|
|
SET archived = 1
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) ArchiveUser(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, archiveUser, id)
|
|
return err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :execresult
|
|
INSERT INTO users (
|
|
username, first_name, last_name, email, type, enabled, archived
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, 0)
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Type UsersType `json:"type"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createUser,
|
|
arg.Username,
|
|
arg.FirstName,
|
|
arg.LastName,
|
|
arg.Email,
|
|
arg.Type,
|
|
arg.Enabled,
|
|
)
|
|
}
|
|
|
|
const getAllUsers = `-- name: GetAllUsers :many
|
|
SELECT id, username, first_name, last_name, email, type, enabled, archived
|
|
FROM users
|
|
WHERE archived = 0
|
|
ORDER BY first_name, last_name
|
|
`
|
|
|
|
type GetAllUsersRow struct {
|
|
ID int32 `json:"id"`
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Type UsersType `json:"type"`
|
|
Enabled bool `json:"enabled"`
|
|
Archived sql.NullBool `json:"archived"`
|
|
}
|
|
|
|
func (q *Queries) GetAllUsers(ctx context.Context) ([]GetAllUsersRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllUsers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetAllUsersRow{}
|
|
for rows.Next() {
|
|
var i GetAllUsersRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.Type,
|
|
&i.Enabled,
|
|
&i.Archived,
|
|
); 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 getUser = `-- name: GetUser :one
|
|
SELECT id, username, first_name, last_name, email, type, enabled, archived
|
|
FROM users
|
|
WHERE id = ?
|
|
`
|
|
|
|
type GetUserRow struct {
|
|
ID int32 `json:"id"`
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Type UsersType `json:"type"`
|
|
Enabled bool `json:"enabled"`
|
|
Archived sql.NullBool `json:"archived"`
|
|
}
|
|
|
|
func (q *Queries) GetUser(ctx context.Context, id int32) (GetUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUser, id)
|
|
var i GetUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.Type,
|
|
&i.Enabled,
|
|
&i.Archived,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
SELECT id, username, first_name, last_name, email, type, enabled, archived
|
|
FROM users
|
|
WHERE username = ? AND archived = 0
|
|
`
|
|
|
|
type GetUserByUsernameRow struct {
|
|
ID int32 `json:"id"`
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Type UsersType `json:"type"`
|
|
Enabled bool `json:"enabled"`
|
|
Archived sql.NullBool `json:"archived"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByUsername, username)
|
|
var i GetUserByUsernameRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Email,
|
|
&i.Type,
|
|
&i.Enabled,
|
|
&i.Archived,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const unarchiveUser = `-- name: UnarchiveUser :exec
|
|
UPDATE users
|
|
SET archived = 0
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) UnarchiveUser(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, unarchiveUser, id)
|
|
return err
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :exec
|
|
UPDATE users
|
|
SET
|
|
username = ?,
|
|
first_name = ?,
|
|
last_name = ?,
|
|
email = ?,
|
|
type = ?,
|
|
enabled = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Email string `json:"email"`
|
|
Type UsersType `json:"type"`
|
|
Enabled bool `json:"enabled"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateUser,
|
|
arg.Username,
|
|
arg.FirstName,
|
|
arg.LastName,
|
|
arg.Email,
|
|
arg.Type,
|
|
arg.Enabled,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|