139 lines
3.1 KiB
Go
139 lines
3.1 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.20.0
|
||
|
// source: issued_codes.sql
|
||
|
|
||
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
)
|
||
|
|
||
|
const assignIssuedCodeSlot = `-- name: AssignIssuedCodeSlot :exec
|
||
|
INSERT INTO issued_code_slots (issued_code, lock, slot) VALUES (?, ?, ?)
|
||
|
`
|
||
|
|
||
|
type AssignIssuedCodeSlotParams struct {
|
||
|
IssuedCode interface{}
|
||
|
Lock interface{}
|
||
|
Slot interface{}
|
||
|
}
|
||
|
|
||
|
func (q *Queries) AssignIssuedCodeSlot(ctx context.Context, arg AssignIssuedCodeSlotParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, assignIssuedCodeSlot, arg.IssuedCode, arg.Lock, arg.Slot)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const createIssuedCode = `-- name: CreateIssuedCode :one
|
||
|
INSERT INTO issued_codes (name, code, start, end) VALUES (?, ?, ?, ?) RETURNING id
|
||
|
`
|
||
|
|
||
|
type CreateIssuedCodeParams struct {
|
||
|
Name sql.NullString
|
||
|
Code string
|
||
|
Start sql.NullTime
|
||
|
End sql.NullTime
|
||
|
}
|
||
|
|
||
|
func (q *Queries) CreateIssuedCode(ctx context.Context, arg CreateIssuedCodeParams) (int64, error) {
|
||
|
row := q.db.QueryRowContext(ctx, createIssuedCode,
|
||
|
arg.Name,
|
||
|
arg.Code,
|
||
|
arg.Start,
|
||
|
arg.End,
|
||
|
)
|
||
|
var id int64
|
||
|
err := row.Scan(&id)
|
||
|
return id, err
|
||
|
}
|
||
|
|
||
|
const deleteIssuedCode = `-- name: DeleteIssuedCode :exec
|
||
|
DELETE FROM issued_codes WHERE id = ?
|
||
|
`
|
||
|
|
||
|
func (q *Queries) DeleteIssuedCode(ctx context.Context, id int64) error {
|
||
|
_, err := q.db.ExecContext(ctx, deleteIssuedCode, id)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
const getActiveCodes = `-- name: GetActiveCodes :many
|
||
|
SELECT id, name, code, start, "end" FROM issued_codes WHERE start < datetime('now') AND end > datetime('now')
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetActiveCodes(ctx context.Context) ([]IssuedCode, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getActiveCodes)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []IssuedCode
|
||
|
for rows.Next() {
|
||
|
var i IssuedCode
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Name,
|
||
|
&i.Code,
|
||
|
&i.Start,
|
||
|
&i.End,
|
||
|
); 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 getAllIssuedCodes = `-- name: GetAllIssuedCodes :many
|
||
|
SELECT id, name, code, start, "end" FROM issued_codes
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetAllIssuedCodes(ctx context.Context) ([]IssuedCode, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getAllIssuedCodes)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []IssuedCode
|
||
|
for rows.Next() {
|
||
|
var i IssuedCode
|
||
|
if err := rows.Scan(
|
||
|
&i.ID,
|
||
|
&i.Name,
|
||
|
&i.Code,
|
||
|
&i.Start,
|
||
|
&i.End,
|
||
|
); 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 unassignIssuedCodeSlot = `-- name: UnassignIssuedCodeSlot :exec
|
||
|
DELETE FROM issued_code_slots WHERE issued_code = ? AND lock = ?
|
||
|
`
|
||
|
|
||
|
type UnassignIssuedCodeSlotParams struct {
|
||
|
IssuedCode interface{}
|
||
|
Lock interface{}
|
||
|
}
|
||
|
|
||
|
func (q *Queries) UnassignIssuedCodeSlot(ctx context.Context, arg UnassignIssuedCodeSlotParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, unassignIssuedCodeSlot, arg.IssuedCode, arg.Lock)
|
||
|
return err
|
||
|
}
|