lockserver/db/lock_log.sql.go

60 lines
1.2 KiB
Go
Raw Normal View History

// 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 getLogForLock = `-- name: GetLogForLock :many
2024-11-23 03:50:18 +00:00
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,
2024-11-23 03:50:18 +00:00
&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
}