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.

174 lines
4.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  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, name 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. &i.Name,
  40. ); err != nil {
  41. return nil, err
  42. }
  43. items = append(items, i)
  44. }
  45. if err := rows.Close(); err != nil {
  46. return nil, err
  47. }
  48. if err := rows.Err(); err != nil {
  49. return nil, err
  50. }
  51. return items, nil
  52. }
  53. const listScriptVariables = `-- name: ListScriptVariables :many
  54. SELECT scope, name, value FROM script_variable
  55. `
  56. func (q *Queries) ListScriptVariables(ctx context.Context) ([]ScriptVariable, error) {
  57. rows, err := q.query(ctx, q.listScriptVariablesStmt, listScriptVariables)
  58. if err != nil {
  59. return nil, err
  60. }
  61. defer rows.Close()
  62. items := []ScriptVariable{}
  63. for rows.Next() {
  64. var i ScriptVariable
  65. if err := rows.Scan(&i.Scope, &i.Name, &i.Value); err != nil {
  66. return nil, err
  67. }
  68. items = append(items, i)
  69. }
  70. if err := rows.Close(); err != nil {
  71. return nil, err
  72. }
  73. if err := rows.Err(); err != nil {
  74. return nil, err
  75. }
  76. return items, nil
  77. }
  78. const listScripts = `-- name: ListScripts :many
  79. SELECT name, data FROM script
  80. `
  81. func (q *Queries) ListScripts(ctx context.Context) ([]Script, error) {
  82. rows, err := q.query(ctx, q.listScriptsStmt, listScripts)
  83. if err != nil {
  84. return nil, err
  85. }
  86. defer rows.Close()
  87. items := []Script{}
  88. for rows.Next() {
  89. var i Script
  90. if err := rows.Scan(&i.Name, &i.Data); err != nil {
  91. return nil, err
  92. }
  93. items = append(items, i)
  94. }
  95. if err := rows.Close(); err != nil {
  96. return nil, err
  97. }
  98. if err := rows.Err(); err != nil {
  99. return nil, err
  100. }
  101. return items, nil
  102. }
  103. const replaceScriptTrigger = `-- name: ReplaceScriptTrigger :exec
  104. REPLACE INTO script_trigger (id, name, event, device_match, parameter, script_target, script_name, script_pre, script_post)
  105. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  106. `
  107. type ReplaceScriptTriggerParams struct {
  108. ID uuid.UUID
  109. Name string
  110. Event string
  111. DeviceMatch string
  112. Parameter string
  113. ScriptTarget string
  114. ScriptName string
  115. ScriptPre json.RawMessage
  116. ScriptPost json.RawMessage
  117. }
  118. func (q *Queries) ReplaceScriptTrigger(ctx context.Context, arg ReplaceScriptTriggerParams) error {
  119. _, err := q.exec(ctx, q.replaceScriptTriggerStmt, replaceScriptTrigger,
  120. arg.ID,
  121. arg.Name,
  122. arg.Event,
  123. arg.DeviceMatch,
  124. arg.Parameter,
  125. arg.ScriptTarget,
  126. arg.ScriptName,
  127. arg.ScriptPre,
  128. arg.ScriptPost,
  129. )
  130. return err
  131. }
  132. const saveScript = `-- name: SaveScript :exec
  133. REPLACE INTO script (name, data) VALUES (?, ?)
  134. `
  135. type SaveScriptParams struct {
  136. Name string
  137. Data json.RawMessage
  138. }
  139. func (q *Queries) SaveScript(ctx context.Context, arg SaveScriptParams) error {
  140. _, err := q.exec(ctx, q.saveScriptStmt, saveScript, arg.Name, arg.Data)
  141. return err
  142. }
  143. const updateScriptVariables = `-- name: UpdateScriptVariables :exec
  144. REPLACE INTO script_variable (scope, name, value) VALUES (?, ?, ?)
  145. `
  146. type UpdateScriptVariablesParams struct {
  147. Scope string
  148. Name string
  149. Value string
  150. }
  151. func (q *Queries) UpdateScriptVariables(ctx context.Context, arg UpdateScriptVariablesParams) error {
  152. _, err := q.exec(ctx, q.updateScriptVariablesStmt, updateScriptVariables, arg.Scope, arg.Name, arg.Value)
  153. return err
  154. }