lockserver/db/user_codes.sql.go

117 lines
2.7 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: user_codes.sql
package db
import (
"context"
"database/sql"
)
const assignUserCodeSlot = `-- name: AssignUserCodeSlot :exec
INSERT INTO user_code_slots (user_code, lock, slot) VALUES (?, ?, ?)
`
type AssignUserCodeSlotParams struct {
UserCode interface{}
Lock interface{}
Slot interface{}
}
func (q *Queries) AssignUserCodeSlot(ctx context.Context, arg AssignUserCodeSlotParams) error {
_, err := q.db.ExecContext(ctx, assignUserCodeSlot, arg.UserCode, arg.Lock, arg.Slot)
return err
}
const createUserCode = `-- name: CreateUserCode :one
INSERT INTO user_codes (user, code, start, end) VALUES (?, ?, ?, ?) RETURNING id
`
type CreateUserCodeParams struct {
User sql.NullInt64
Code string
Start sql.NullTime
End sql.NullTime
}
func (q *Queries) CreateUserCode(ctx context.Context, arg CreateUserCodeParams) (int64, error) {
row := q.db.QueryRowContext(ctx, createUserCode,
arg.User,
arg.Code,
arg.Start,
arg.End,
)
var id int64
err := row.Scan(&id)
return id, err
}
const deleteUserCode = `-- name: DeleteUserCode :exec
DELETE FROM user_codes WHERE id = ?
`
func (q *Queries) DeleteUserCode(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteUserCode, id)
return err
}
const getAllUserCodes = `-- name: GetAllUserCodes :many
SELECT user_codes.id, user_codes.user, user_codes.name, user_codes.code, user_codes.start, user_codes."end", users.name FROM user_codes, users WHERE user_codes.user = users.id
`
type GetAllUserCodesRow struct {
ID int64
User sql.NullInt64
Name sql.NullString
Code string
Start sql.NullTime
End sql.NullTime
Name_2 string
}
func (q *Queries) GetAllUserCodes(ctx context.Context) ([]GetAllUserCodesRow, error) {
rows, err := q.db.QueryContext(ctx, getAllUserCodes)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetAllUserCodesRow
for rows.Next() {
var i GetAllUserCodesRow
if err := rows.Scan(
&i.ID,
&i.User,
&i.Name,
&i.Code,
&i.Start,
&i.End,
&i.Name_2,
); 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 unassignUserCodeSlot = `-- name: UnassignUserCodeSlot :exec
DELETE FROM user_code_slots WHERE user_code = ? AND lock = ?
`
type UnassignUserCodeSlotParams struct {
UserCode interface{}
Lock interface{}
}
func (q *Queries) UnassignUserCodeSlot(ctx context.Context, arg UnassignUserCodeSlotParams) error {
_, err := q.db.ExecContext(ctx, unassignUserCodeSlot, arg.UserCode, arg.Lock)
return err
}