lockserver/db/lock_code_slots.sql.go

89 lines
1.9 KiB
Go
Raw Permalink Normal View History

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: lock_code_slots.sql
package db
import (
"context"
)
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
}
const getLockCodes = `-- name: GetLockCodes :many
SELECT id, lock, code, slot, name, enabled FROM lock_code_slots WHERE lock = ?
`
func (q *Queries) GetLockCodes(ctx context.Context, lock int64) ([]LockCodeSlot, error) {
rows, err := q.db.QueryContext(ctx, getLockCodes, 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 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
}