GraphQL API and utilities for the rpdata project
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.

138 lines
3.3 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: changes.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. "encoding/json"
  7. "time"
  8. "github.com/lib/pq"
  9. )
  10. const deleteChange = `-- name: DeleteChange :exec
  11. DELETE FROM data_change WHERE id = $1
  12. `
  13. func (q *Queries) DeleteChange(ctx context.Context, id string) error {
  14. _, err := q.db.ExecContext(ctx, deleteChange, id)
  15. return err
  16. }
  17. const insertChange = `-- name: InsertChange :exec
  18. INSERT INTO data_change (id, model, op, author, listed, date, keys, objects)
  19. VALUES (
  20. $1::text, $2::text, $3::text, $4::text,
  21. $5::boolean, $6::timestamp, $7::text[],
  22. $8::jsonb
  23. )
  24. `
  25. type InsertChangeParams struct {
  26. ID string `json:"id"`
  27. Model string `json:"model"`
  28. Op string `json:"op"`
  29. Author string `json:"author"`
  30. Listed bool `json:"listed"`
  31. Date time.Time `json:"date"`
  32. Keys []string `json:"keys"`
  33. Objects json.RawMessage `json:"objects"`
  34. }
  35. func (q *Queries) InsertChange(ctx context.Context, arg InsertChangeParams) error {
  36. _, err := q.db.ExecContext(ctx, insertChange,
  37. arg.ID,
  38. arg.Model,
  39. arg.Op,
  40. arg.Author,
  41. arg.Listed,
  42. arg.Date,
  43. pq.Array(arg.Keys),
  44. arg.Objects,
  45. )
  46. return err
  47. }
  48. const selectChangeByID = `-- name: SelectChangeByID :one
  49. SELECT id, model, op, author, listed, date, keys, objects FROM data_change WHERE id = $1 LIMIT 1
  50. `
  51. func (q *Queries) SelectChangeByID(ctx context.Context, id string) (DataChange, error) {
  52. row := q.db.QueryRowContext(ctx, selectChangeByID, id)
  53. var i DataChange
  54. err := row.Scan(
  55. &i.ID,
  56. &i.Model,
  57. &i.Op,
  58. &i.Author,
  59. &i.Listed,
  60. &i.Date,
  61. pq.Array(&i.Keys),
  62. &i.Objects,
  63. )
  64. return i, err
  65. }
  66. const selectChanges = `-- name: SelectChanges :many
  67. SELECT id, model, op, author, listed, date, keys, objects FROM data_change
  68. WHERE ($1::bool = false OR keys && ($2::text[]))
  69. AND ($3::bool = false OR date >= $4::timestamp)
  70. AND ($5::bool = false OR date <= $6::timestamp)
  71. AND ($7::bool = false OR author = $8::text)
  72. LIMIT $9::int
  73. `
  74. type SelectChangesParams struct {
  75. FilterKeys bool `json:"filter_keys"`
  76. Keys []string `json:"keys"`
  77. FilterEarliestDate bool `json:"filter_earliest_date"`
  78. EarliestDate time.Time `json:"earliest_date"`
  79. FilterLatestDate bool `json:"filter_latest_date"`
  80. LatestDate time.Time `json:"latest_date"`
  81. FilterAuthor bool `json:"filter_author"`
  82. Author string `json:"author"`
  83. LimitSize int32 `json:"limit_size"`
  84. }
  85. func (q *Queries) SelectChanges(ctx context.Context, arg SelectChangesParams) ([]DataChange, error) {
  86. rows, err := q.db.QueryContext(ctx, selectChanges,
  87. arg.FilterKeys,
  88. pq.Array(arg.Keys),
  89. arg.FilterEarliestDate,
  90. arg.EarliestDate,
  91. arg.FilterLatestDate,
  92. arg.LatestDate,
  93. arg.FilterAuthor,
  94. arg.Author,
  95. arg.LimitSize,
  96. )
  97. if err != nil {
  98. return nil, err
  99. }
  100. defer rows.Close()
  101. items := []DataChange{}
  102. for rows.Next() {
  103. var i DataChange
  104. if err := rows.Scan(
  105. &i.ID,
  106. &i.Model,
  107. &i.Op,
  108. &i.Author,
  109. &i.Listed,
  110. &i.Date,
  111. pq.Array(&i.Keys),
  112. &i.Objects,
  113. ); err != nil {
  114. return nil, err
  115. }
  116. items = append(items, i)
  117. }
  118. if err := rows.Close(); err != nil {
  119. return nil, err
  120. }
  121. if err := rows.Err(); err != nil {
  122. return nil, err
  123. }
  124. return items, nil
  125. }