Initial commit

Connects to zwave-js, syncs all locks and codeslots with database, and records an event log. No support for updating code slots.
This commit is contained in:
Finn 2024-04-08 21:25:36 -07:00
commit 054008eb1f
20 changed files with 1165 additions and 0 deletions

View file

@ -0,0 +1,8 @@
-- 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;
-- name: GetLockCodeBySlot :one
SELECT * FROM lock_code_slots WHERE lock = ? AND slot = ?;
-- name: GetLockCodes :many
SELECT * FROM lock_code_slots WHERE lock = ?;

5
db/queries/lock_log.sql Normal file
View file

@ -0,0 +1,5 @@
-- name: AddLogEntry :exec
INSERT INTO lock_log (lock, state, code) VALUES (?, ?, ?);
-- name: GetLogForLock :many
SELECT * FROM lock_log WHERE lock = ? ORDER BY timestamp DESC;

11
db/queries/locks.sql Normal file
View file

@ -0,0 +1,11 @@
-- name: CreateLock :one
INSERT INTO locks (zwave_device_id, name) VALUES (?, "") RETURNING *;
-- name: GetLocks :many
SELECT * FROM locks;
-- name: GetLockByDeviceID :one
SELECT * FROM locks WHERE zwave_device_id = ?;
-- name: UpdateLockName :exec
UPDATE locks SET name = ? WHERE id = ?;