You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.0 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.13.0
  4. // source: script.sql
  5. package mysqlgen
  6. import (
  7. "context"
  8. "encoding/json"
  9. "github.com/google/uuid"
  10. )
  11. const deleteScriptTrigger = `-- name: DeleteScriptTrigger :exec
  12. DELETE FROM script_trigger WHERE id = ?
  13. `
  14. func (q *Queries) DeleteScriptTrigger(ctx context.Context, id uuid.UUID) error {
  15. _, err := q.exec(ctx, q.deleteScriptTriggerStmt, deleteScriptTrigger, id)
  16. return err
  17. }
  18. const listScriptTriggers = `-- name: ListScriptTriggers :many
  19. SELECT id, event, device_match, parameter, script_target, script_name, script_pre, script_post FROM script_trigger
  20. `
  21. func (q *Queries) ListScriptTriggers(ctx context.Context) ([]ScriptTrigger, error) {
  22. rows, err := q.query(ctx, q.listScriptTriggersStmt, listScriptTriggers)
  23. if err != nil {
  24. return nil, err
  25. }
  26. defer rows.Close()
  27. items := []ScriptTrigger{}
  28. for rows.Next() {
  29. var i ScriptTrigger
  30. if err := rows.Scan(
  31. &i.ID,
  32. &i.Event,
  33. &i.DeviceMatch,
  34. &i.Parameter,
  35. &i.ScriptTarget,
  36. &i.ScriptName,
  37. &i.ScriptPre,
  38. &i.ScriptPost,
  39. ); err != nil {
  40. return nil, err
  41. }
  42. items = append(items, i)
  43. }
  44. if err := rows.Close(); err != nil {
  45. return nil, err
  46. }
  47. if err := rows.Err(); err != nil {
  48. return nil, err
  49. }
  50. return items, nil
  51. }
  52. const listScriptVariables = `-- name: ListScriptVariables :many
  53. SELECT scope, name, value FROM script_variable
  54. `
  55. func (q *Queries) ListScriptVariables(ctx context.Context) ([]ScriptVariable, error) {
  56. rows, err := q.query(ctx, q.listScriptVariablesStmt, listScriptVariables)
  57. if err != nil {
  58. return nil, err
  59. }
  60. defer rows.Close()
  61. items := []ScriptVariable{}
  62. for rows.Next() {
  63. var i ScriptVariable
  64. if err := rows.Scan(&i.Scope, &i.Name, &i.Value); err != nil {
  65. return nil, err
  66. }
  67. items = append(items, i)
  68. }
  69. if err := rows.Close(); err != nil {
  70. return nil, err
  71. }
  72. if err := rows.Err(); err != nil {
  73. return nil, err
  74. }
  75. return items, nil
  76. }
  77. const listScripts = `-- name: ListScripts :many
  78. SELECT name, data FROM script
  79. `
  80. func (q *Queries) ListScripts(ctx context.Context) ([]Script, error) {
  81. rows, err := q.query(ctx, q.listScriptsStmt, listScripts)
  82. if err != nil {
  83. return nil, err
  84. }
  85. defer rows.Close()
  86. items := []Script{}
  87. for rows.Next() {
  88. var i Script
  89. if err := rows.Scan(&i.Name, &i.Data); err != nil {
  90. return nil, err
  91. }
  92. items = append(items, i)
  93. }
  94. if err := rows.Close(); err != nil {
  95. return nil, err
  96. }
  97. if err := rows.Err(); err != nil {
  98. return nil, err
  99. }
  100. return items, nil
  101. }
  102. const replaceScriptTrigger = `-- name: ReplaceScriptTrigger :exec
  103. REPLACE INTO script_trigger (id, event, device_match, parameter, script_target, script_name, script_pre, script_post)
  104. VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  105. `
  106. type ReplaceScriptTriggerParams struct {
  107. ID uuid.UUID
  108. Event string
  109. DeviceMatch string
  110. Parameter string
  111. ScriptTarget string
  112. ScriptName string
  113. ScriptPre json.RawMessage
  114. ScriptPost json.RawMessage
  115. }
  116. func (q *Queries) ReplaceScriptTrigger(ctx context.Context, arg ReplaceScriptTriggerParams) error {
  117. _, err := q.exec(ctx, q.replaceScriptTriggerStmt, replaceScriptTrigger,
  118. arg.ID,
  119. arg.Event,
  120. arg.DeviceMatch,
  121. arg.Parameter,
  122. arg.ScriptTarget,
  123. arg.ScriptName,
  124. arg.ScriptPre,
  125. arg.ScriptPost,
  126. )
  127. return err
  128. }
  129. const saveScript = `-- name: SaveScript :exec
  130. REPLACE INTO script (name, data) VALUES (?, ?)
  131. `
  132. type SaveScriptParams struct {
  133. Name string
  134. Data json.RawMessage
  135. }
  136. func (q *Queries) SaveScript(ctx context.Context, arg SaveScriptParams) error {
  137. _, err := q.exec(ctx, q.saveScriptStmt, saveScript, arg.Name, arg.Data)
  138. return err
  139. }
  140. const updateScriptVariables = `-- name: UpdateScriptVariables :exec
  141. REPLACE INTO script_variable (scope, name, value) VALUES (?, ?, ?)
  142. `
  143. type UpdateScriptVariablesParams struct {
  144. Scope string
  145. Name string
  146. Value string
  147. }
  148. func (q *Queries) UpdateScriptVariables(ctx context.Context, arg UpdateScriptVariablesParams) error {
  149. _, err := q.exec(ctx, q.updateScriptVariablesStmt, updateScriptVariables, arg.Scope, arg.Name, arg.Value)
  150. return err
  151. }