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.

183 lines
4.3 KiB

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