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.

139 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. ORDER BY date DESC
  73. LIMIT $9::int
  74. `
  75. type SelectChangesParams struct {
  76. FilterKeys bool `json:"filter_keys"`
  77. Keys []string `json:"keys"`
  78. FilterEarliestDate bool `json:"filter_earliest_date"`
  79. EarliestDate time.Time `json:"earliest_date"`
  80. FilterLatestDate bool `json:"filter_latest_date"`
  81. LatestDate time.Time `json:"latest_date"`
  82. FilterAuthor bool `json:"filter_author"`
  83. Author string `json:"author"`
  84. LimitSize int32 `json:"limit_size"`
  85. }
  86. func (q *Queries) SelectChanges(ctx context.Context, arg SelectChangesParams) ([]DataChange, error) {
  87. rows, err := q.db.QueryContext(ctx, selectChanges,
  88. arg.FilterKeys,
  89. pq.Array(arg.Keys),
  90. arg.FilterEarliestDate,
  91. arg.EarliestDate,
  92. arg.FilterLatestDate,
  93. arg.LatestDate,
  94. arg.FilterAuthor,
  95. arg.Author,
  96. arg.LimitSize,
  97. )
  98. if err != nil {
  99. return nil, err
  100. }
  101. defer rows.Close()
  102. items := []DataChange{}
  103. for rows.Next() {
  104. var i DataChange
  105. if err := rows.Scan(
  106. &i.ID,
  107. &i.Model,
  108. &i.Op,
  109. &i.Author,
  110. &i.Listed,
  111. &i.Date,
  112. pq.Array(&i.Keys),
  113. &i.Objects,
  114. ); err != nil {
  115. return nil, err
  116. }
  117. items = append(items, i)
  118. }
  119. if err := rows.Close(); err != nil {
  120. return nil, err
  121. }
  122. if err := rows.Err(); err != nil {
  123. return nil, err
  124. }
  125. return items, nil
  126. }