mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-11 08:18:52 -06:00
238 lines
6.0 KiB
Go
238 lines
6.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO backend.users (name, email, subscription_id) VALUES ($1, $2, $3) RETURNING id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Name string `db:"name" json:"name"`
|
|
Email string `db:"email" json:"email"`
|
|
SubscriptionID pgtype.Int4 `db:"subscription_id" json:"subscription_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg *CreateUserParams) (*User, error) {
|
|
row := q.db.QueryRow(ctx, createUser, arg.Name, arg.Email, arg.SubscriptionID)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const deleteUsers = `-- name: DeleteUsers :exec
|
|
DELETE FROM backend.users WHERE id = ANY($1::INT[])
|
|
`
|
|
|
|
func (q *Queries) DeleteUsers(ctx context.Context, dollar_1 []int32) error {
|
|
_, err := q.db.Exec(ctx, deleteUsers, dollar_1)
|
|
return err
|
|
}
|
|
|
|
const getSoftDeletedUsers = `-- name: GetSoftDeletedUsers :many
|
|
SELECT u.id, u.name, u.email, u.subscription_id, u.created_at, u.updated_at, u.deleted_at, u.enabled
|
|
FROM backend.users u
|
|
WHERE u.deleted_at IS NOT NULL
|
|
AND u.deleted_at < $1
|
|
LIMIT $2
|
|
`
|
|
|
|
type GetSoftDeletedUsersParams struct {
|
|
DeletedAt pgtype.Timestamptz `db:"deleted_at" json:"deleted_at"`
|
|
Limit int32 `db:"limit" json:"limit"`
|
|
}
|
|
|
|
type GetSoftDeletedUsersRow struct {
|
|
User User `db:"user" json:"user"`
|
|
}
|
|
|
|
func (q *Queries) GetSoftDeletedUsers(ctx context.Context, arg *GetSoftDeletedUsersParams) ([]*GetSoftDeletedUsersRow, error) {
|
|
rows, err := q.db.Query(ctx, getSoftDeletedUsers, arg.DeletedAt, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*GetSoftDeletedUsersRow
|
|
for rows.Next() {
|
|
var i GetSoftDeletedUsersRow
|
|
if err := rows.Scan(
|
|
&i.User.ID,
|
|
&i.User.Name,
|
|
&i.User.Email,
|
|
&i.User.SubscriptionID,
|
|
&i.User.CreatedAt,
|
|
&i.User.UpdatedAt,
|
|
&i.User.DeletedAt,
|
|
&i.User.Enabled,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getUserByEmail = `-- name: GetUserByEmail :one
|
|
SELECT id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled FROM backend.users WHERE email = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (*User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByEmail, email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled FROM backend.users WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id int32) (*User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getUsersWithoutSubscription = `-- name: GetUsersWithoutSubscription :many
|
|
SELECT id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled FROM backend.users where id = ANY($1::INT[]) AND (subscription_id IS NULL OR deleted_at IS NOT NULL)
|
|
`
|
|
|
|
func (q *Queries) GetUsersWithoutSubscription(ctx context.Context, dollar_1 []int32) ([]*User, error) {
|
|
rows, err := q.db.Query(ctx, getUsersWithoutSubscription, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*User
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const softDeleteUser = `-- name: SoftDeleteUser :one
|
|
UPDATE backend.users SET deleted_at = NOW() WHERE id = $1 RETURNING id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteUser(ctx context.Context, id int32) (*User, error) {
|
|
row := q.db.QueryRow(ctx, softDeleteUser, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const updateUserData = `-- name: UpdateUserData :one
|
|
UPDATE backend.users SET name = $2, email = $3, updated_at = NOW() WHERE id = $1 RETURNING id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled
|
|
`
|
|
|
|
type UpdateUserDataParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
Email string `db:"email" json:"email"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserData(ctx context.Context, arg *UpdateUserDataParams) (*User, error) {
|
|
row := q.db.QueryRow(ctx, updateUserData, arg.ID, arg.Name, arg.Email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const updateUserSubscription = `-- name: UpdateUserSubscription :one
|
|
UPDATE backend.users SET subscription_id = $2, updated_at = NOW() WHERE id = $1 RETURNING id, name, email, subscription_id, created_at, updated_at, deleted_at, enabled
|
|
`
|
|
|
|
type UpdateUserSubscriptionParams struct {
|
|
ID int32 `db:"id" json:"id"`
|
|
SubscriptionID pgtype.Int4 `db:"subscription_id" json:"subscription_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserSubscription(ctx context.Context, arg *UpdateUserSubscriptionParams) (*User, error) {
|
|
row := q.db.QueryRow(ctx, updateUserSubscription, arg.ID, arg.SubscriptionID)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Email,
|
|
&i.SubscriptionID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.DeletedAt,
|
|
&i.Enabled,
|
|
)
|
|
return &i, err
|
|
}
|