74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
// versions:
|
||
|
// sqlc v1.20.0
|
||
|
// source: locks.sql
|
||
|
|
||
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
const createLock = `-- name: CreateLock :one
|
||
|
INSERT INTO locks (zwave_device_id, name) VALUES (?, "") RETURNING id, name, zwave_device_id
|
||
|
`
|
||
|
|
||
|
func (q *Queries) CreateLock(ctx context.Context, zwaveDeviceID int64) (Lock, error) {
|
||
|
row := q.db.QueryRowContext(ctx, createLock, zwaveDeviceID)
|
||
|
var i Lock
|
||
|
err := row.Scan(&i.ID, &i.Name, &i.ZwaveDeviceID)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getLockByDeviceID = `-- name: GetLockByDeviceID :one
|
||
|
SELECT id, name, zwave_device_id FROM locks WHERE zwave_device_id = ?
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetLockByDeviceID(ctx context.Context, zwaveDeviceID int64) (Lock, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getLockByDeviceID, zwaveDeviceID)
|
||
|
var i Lock
|
||
|
err := row.Scan(&i.ID, &i.Name, &i.ZwaveDeviceID)
|
||
|
return i, err
|
||
|
}
|
||
|
|
||
|
const getLocks = `-- name: GetLocks :many
|
||
|
SELECT id, name, zwave_device_id FROM locks
|
||
|
`
|
||
|
|
||
|
func (q *Queries) GetLocks(ctx context.Context) ([]Lock, error) {
|
||
|
rows, err := q.db.QueryContext(ctx, getLocks)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
var items []Lock
|
||
|
for rows.Next() {
|
||
|
var i Lock
|
||
|
if err := rows.Scan(&i.ID, &i.Name, &i.ZwaveDeviceID); 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 updateLockName = `-- name: UpdateLockName :exec
|
||
|
UPDATE locks SET name = ? WHERE id = ?
|
||
|
`
|
||
|
|
||
|
type UpdateLockNameParams struct {
|
||
|
Name string
|
||
|
ID int64
|
||
|
}
|
||
|
|
||
|
func (q *Queries) UpdateLockName(ctx context.Context, arg UpdateLockNameParams) error {
|
||
|
_, err := q.db.ExecContext(ctx, updateLockName, arg.Name, arg.ID)
|
||
|
return err
|
||
|
}
|