lockserver/db/lock_code_slots.sql.go

175 lines
3.8 KiB
Go
Raw Normal View History

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: lock_code_slots.sql
package db
import (
"context"
)
2024-11-23 03:50:18 +00:00
const countUsedSlots = `-- name: CountUsedSlots :one
SELECT COUNT(*) FROM lock_code_slots WHERE lock = ? AND enabled = 1
`
func (q *Queries) CountUsedSlots(ctx context.Context, lock int64) (int64, error) {
row := q.db.QueryRowContext(ctx, countUsedSlots, lock)
var count int64
err := row.Scan(&count)
return count, err
}
const getAllLockCodesByLock = `-- name: GetAllLockCodesByLock :many
SELECT id, lock, code, slot, name, enabled FROM lock_code_slots WHERE lock = ?
`
func (q *Queries) GetAllLockCodesByLock(ctx context.Context, lock int64) ([]LockCodeSlot, error) {
rows, err := q.db.QueryContext(ctx, getAllLockCodesByLock, lock)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockCodeSlot
for rows.Next() {
var i LockCodeSlot
if err := rows.Scan(
&i.ID,
&i.Lock,
&i.Code,
&i.Slot,
&i.Name,
&i.Enabled,
); 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 getEmptySlot = `-- name: GetEmptySlot :one
SELECT id, lock, code, slot, name, enabled FROM lock_code_slots WHERE lock = ? AND enabled = 0 LIMIT 1
`
func (q *Queries) GetEmptySlot(ctx context.Context, lock int64) (LockCodeSlot, error) {
row := q.db.QueryRowContext(ctx, getEmptySlot, lock)
var i LockCodeSlot
err := row.Scan(
&i.ID,
&i.Lock,
&i.Code,
&i.Slot,
&i.Name,
&i.Enabled,
)
return i, err
}
const getLockCodeBySlot = `-- name: GetLockCodeBySlot :one
SELECT id, lock, code, slot, name, enabled FROM lock_code_slots WHERE lock = ? AND slot = ?
`
type GetLockCodeBySlotParams struct {
Lock int64
Slot int64
}
func (q *Queries) GetLockCodeBySlot(ctx context.Context, arg GetLockCodeBySlotParams) (LockCodeSlot, error) {
row := q.db.QueryRowContext(ctx, getLockCodeBySlot, arg.Lock, arg.Slot)
var i LockCodeSlot
err := row.Scan(
&i.ID,
&i.Lock,
&i.Code,
&i.Slot,
&i.Name,
&i.Enabled,
)
return i, err
}
2024-11-23 03:50:18 +00:00
const getLockCodesByCode = `-- name: GetLockCodesByCode :many
SELECT id, lock, code, slot, name, enabled FROM lock_code_slots WHERE code = ?
`
2024-11-23 03:50:18 +00:00
func (q *Queries) GetLockCodesByCode(ctx context.Context, code string) ([]LockCodeSlot, error) {
rows, err := q.db.QueryContext(ctx, getLockCodesByCode, code)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockCodeSlot
for rows.Next() {
var i LockCodeSlot
if err := rows.Scan(
&i.ID,
&i.Lock,
&i.Code,
&i.Slot,
&i.Name,
&i.Enabled,
); 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 updateCodeSlot = `-- name: UpdateCodeSlot :exec
UPDATE lock_code_slots SET code = ?, enabled = ?, name = ? WHERE lock = ? AND slot = ?
`
type UpdateCodeSlotParams struct {
Code string
Enabled bool
Name string
Lock int64
Slot int64
}
func (q *Queries) UpdateCodeSlot(ctx context.Context, arg UpdateCodeSlotParams) error {
_, err := q.db.ExecContext(ctx, updateCodeSlot,
arg.Code,
arg.Enabled,
arg.Name,
arg.Lock,
arg.Slot,
)
return err
}
const upsertCodeSlot = `-- name: UpsertCodeSlot :exec
INSERT INTO lock_code_slots (lock, slot, code, enabled, name) VALUES (?, ?, ?, ?, "") ON CONFLICT (lock, slot) DO UPDATE SET code=excluded.code, enabled=excluded.enabled
`
type UpsertCodeSlotParams struct {
Lock int64
Slot int64
Code string
Enabled bool
}
func (q *Queries) UpsertCodeSlot(ctx context.Context, arg UpsertCodeSlotParams) error {
_, err := q.db.ExecContext(ctx, upsertCodeSlot,
arg.Lock,
arg.Slot,
arg.Code,
arg.Enabled,
)
return err
}