lockserver/db/lock_log.sql.go

59 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
SELECT lock, timestamp, state, 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,
); 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
}