lockserver/db/lock_log.sql.go
Finn 4627ae91b3
All checks were successful
/ build-container (push) Successful in 8m0s
add readme and limit log entry counts displayed
2024-11-24 16:36:18 -08:00

135 lines
2.9 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: lock_log.sql
package db
import (
"context"
"database/sql"
)
const addLogEntry = `-- name: AddLogEntry :exec
INSERT INTO lock_log (lock, state, code) VALUES (?, ?, ?)
`
type AddLogEntryParams struct {
Lock int64
State string
Code sql.NullInt64
}
func (q *Queries) AddLogEntry(ctx context.Context, arg AddLogEntryParams) error {
_, err := q.db.ExecContext(ctx, addLogEntry, arg.Lock, arg.State, arg.Code)
return err
}
const getLastLogForSlot = `-- name: GetLastLogForSlot :many
SELECT lock, timestamp, state, code, issued_code FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC LIMIT 1
`
type GetLastLogForSlotParams struct {
Lock int64
Code sql.NullInt64
}
func (q *Queries) GetLastLogForSlot(ctx context.Context, arg GetLastLogForSlotParams) ([]LockLog, error) {
rows, err := q.db.QueryContext(ctx, getLastLogForSlot, arg.Lock, arg.Code)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockLog
for rows.Next() {
var i LockLog
if err := rows.Scan(
&i.Lock,
&i.Timestamp,
&i.State,
&i.Code,
&i.IssuedCode,
); 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 getLogForLock = `-- name: GetLogForLock :many
SELECT lock, timestamp, state, code, issued_code FROM lock_log WHERE lock = ? ORDER BY timestamp DESC
`
func (q *Queries) GetLogForLock(ctx context.Context, lock int64) ([]LockLog, error) {
rows, err := q.db.QueryContext(ctx, getLogForLock, lock)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockLog
for rows.Next() {
var i LockLog
if err := rows.Scan(
&i.Lock,
&i.Timestamp,
&i.State,
&i.Code,
&i.IssuedCode,
); 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 getLogForSlot = `-- name: GetLogForSlot :many
SELECT lock, timestamp, state, code, issued_code FROM lock_log WHERE lock = ? AND code = ? ORDER BY timestamp DESC LIMIT 100
`
type GetLogForSlotParams struct {
Lock int64
Code sql.NullInt64
}
func (q *Queries) GetLogForSlot(ctx context.Context, arg GetLogForSlotParams) ([]LockLog, error) {
rows, err := q.db.QueryContext(ctx, getLogForSlot, arg.Lock, arg.Code)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LockLog
for rows.Next() {
var i LockLog
if err := rows.Scan(
&i.Lock,
&i.Timestamp,
&i.State,
&i.Code,
&i.IssuedCode,
); 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
}