scripting system, hue fixes and such
This commit is contained in:
@@ -63,6 +63,12 @@ func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
if q.listDeviceInfosStmt, err = db.PrepareContext(ctx, listDeviceInfos); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListDeviceInfos: %w", err)
|
||||
}
|
||||
if q.listScriptVariablesStmt, err = db.PrepareContext(ctx, listScriptVariables); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListScriptVariables: %w", err)
|
||||
}
|
||||
if q.listScriptsStmt, err = db.PrepareContext(ctx, listScripts); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListScripts: %w", err)
|
||||
}
|
||||
if q.replaceDeviceAssignmentStmt, err = db.PrepareContext(ctx, replaceDeviceAssignment); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ReplaceDeviceAssignment: %w", err)
|
||||
}
|
||||
@@ -72,6 +78,12 @@ func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
if q.replaceDeviceInfoStmt, err = db.PrepareContext(ctx, replaceDeviceInfo); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ReplaceDeviceInfo: %w", err)
|
||||
}
|
||||
if q.saveScriptStmt, err = db.PrepareContext(ctx, saveScript); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query SaveScript: %w", err)
|
||||
}
|
||||
if q.updateScriptVariablesStmt, err = db.PrepareContext(ctx, updateScriptVariables); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query UpdateScriptVariables: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
@@ -142,6 +154,16 @@ func (q *Queries) Close() error {
|
||||
err = fmt.Errorf("error closing listDeviceInfosStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listScriptVariablesStmt != nil {
|
||||
if cerr := q.listScriptVariablesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listScriptVariablesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listScriptsStmt != nil {
|
||||
if cerr := q.listScriptsStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listScriptsStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.replaceDeviceAssignmentStmt != nil {
|
||||
if cerr := q.replaceDeviceAssignmentStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing replaceDeviceAssignmentStmt: %w", cerr)
|
||||
@@ -157,6 +179,16 @@ func (q *Queries) Close() error {
|
||||
err = fmt.Errorf("error closing replaceDeviceInfoStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.saveScriptStmt != nil {
|
||||
if cerr := q.saveScriptStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing saveScriptStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.updateScriptVariablesStmt != nil {
|
||||
if cerr := q.updateScriptVariablesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing updateScriptVariablesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -209,9 +241,13 @@ type Queries struct {
|
||||
listDeviceAssignmentsStmt *sql.Stmt
|
||||
listDeviceAuthStmt *sql.Stmt
|
||||
listDeviceInfosStmt *sql.Stmt
|
||||
listScriptVariablesStmt *sql.Stmt
|
||||
listScriptsStmt *sql.Stmt
|
||||
replaceDeviceAssignmentStmt *sql.Stmt
|
||||
replaceDeviceAuthStmt *sql.Stmt
|
||||
replaceDeviceInfoStmt *sql.Stmt
|
||||
saveScriptStmt *sql.Stmt
|
||||
updateScriptVariablesStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
@@ -231,8 +267,12 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
listDeviceAssignmentsStmt: q.listDeviceAssignmentsStmt,
|
||||
listDeviceAuthStmt: q.listDeviceAuthStmt,
|
||||
listDeviceInfosStmt: q.listDeviceInfosStmt,
|
||||
listScriptVariablesStmt: q.listScriptVariablesStmt,
|
||||
listScriptsStmt: q.listScriptsStmt,
|
||||
replaceDeviceAssignmentStmt: q.replaceDeviceAssignmentStmt,
|
||||
replaceDeviceAuthStmt: q.replaceDeviceAuthStmt,
|
||||
replaceDeviceInfoStmt: q.replaceDeviceInfoStmt,
|
||||
saveScriptStmt: q.saveScriptStmt,
|
||||
updateScriptVariablesStmt: q.updateScriptVariablesStmt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,3 +34,14 @@ type DeviceInfo struct {
|
||||
Kind string
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
type Script struct {
|
||||
Name string
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
type ScriptVariable struct {
|
||||
Scope string
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.13.0
|
||||
// source: script.sql
|
||||
|
||||
package mysqlgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const listScriptVariables = `-- name: ListScriptVariables :many
|
||||
SELECT scope, name, value FROM script_variable
|
||||
`
|
||||
|
||||
func (q *Queries) ListScriptVariables(ctx context.Context) ([]ScriptVariable, error) {
|
||||
rows, err := q.query(ctx, q.listScriptVariablesStmt, listScriptVariables)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ScriptVariable{}
|
||||
for rows.Next() {
|
||||
var i ScriptVariable
|
||||
if err := rows.Scan(&i.Scope, &i.Name, &i.Value); 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 listScripts = `-- name: ListScripts :many
|
||||
SELECT name, data FROM script
|
||||
`
|
||||
|
||||
func (q *Queries) ListScripts(ctx context.Context) ([]Script, error) {
|
||||
rows, err := q.query(ctx, q.listScriptsStmt, listScripts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Script{}
|
||||
for rows.Next() {
|
||||
var i Script
|
||||
if err := rows.Scan(&i.Name, &i.Data); 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 saveScript = `-- name: SaveScript :exec
|
||||
REPLACE INTO script (name, data) VALUES (?, ?)
|
||||
`
|
||||
|
||||
type SaveScriptParams struct {
|
||||
Name string
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
func (q *Queries) SaveScript(ctx context.Context, arg SaveScriptParams) error {
|
||||
_, err := q.exec(ctx, q.saveScriptStmt, saveScript, arg.Name, arg.Data)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateScriptVariables = `-- name: UpdateScriptVariables :exec
|
||||
REPLACE INTO script_variable (scope, name, value) VALUES (?, ?, ?)
|
||||
`
|
||||
|
||||
type UpdateScriptVariablesParams struct {
|
||||
Scope string
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateScriptVariables(ctx context.Context, arg UpdateScriptVariablesParams) error {
|
||||
_, err := q.exec(ctx, q.updateScriptVariablesStmt, updateScriptVariables, arg.Scope, arg.Name, arg.Value)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user