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.

200 lines
5.4 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: stories.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. "time"
  7. "github.com/lib/pq"
  8. )
  9. const deleteStory = `-- name: DeleteStory :exec
  10. DELETE FROM story WHERE id=$1
  11. `
  12. func (q *Queries) DeleteStory(ctx context.Context, id string) error {
  13. _, err := q.db.ExecContext(ctx, deleteStory, id)
  14. return err
  15. }
  16. const insertStory = `-- name: InsertStory :exec
  17. INSERT INTO story (id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date)
  18. VALUES (
  19. $1::text, $2::text, $3::text, $4::text,
  20. $5::boolean, $6::boolean, $7::boolean,
  21. $8::timestamp, $9::timestamp, $10::timestamp
  22. )
  23. `
  24. type InsertStoryParams struct {
  25. ID string `json:"id"`
  26. Author string `json:"author"`
  27. Name string `json:"name"`
  28. Category string `json:"category"`
  29. Open bool `json:"open"`
  30. Listed bool `json:"listed"`
  31. SortByFictionalDate bool `json:"sort_by_fictional_date"`
  32. CreatedDate time.Time `json:"created_date"`
  33. FictionalDate time.Time `json:"fictional_date"`
  34. UpdatedDate time.Time `json:"updated_date"`
  35. }
  36. func (q *Queries) InsertStory(ctx context.Context, arg InsertStoryParams) error {
  37. _, err := q.db.ExecContext(ctx, insertStory,
  38. arg.ID,
  39. arg.Author,
  40. arg.Name,
  41. arg.Category,
  42. arg.Open,
  43. arg.Listed,
  44. arg.SortByFictionalDate,
  45. arg.CreatedDate,
  46. arg.FictionalDate,
  47. arg.UpdatedDate,
  48. )
  49. return err
  50. }
  51. const selectStories = `-- name: SelectStories :many
  52. SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story
  53. WHERE ($1::bool = false OR id = ANY($2::text[]))
  54. AND ($3::bool = false OR name = $4::text)
  55. AND ($5::bool = false OR fictional_date >= $6::timestamp)
  56. AND ($7::bool = false OR fictional_date <= $8::timestamp)
  57. AND ($9::bool = false OR category = $10::text)
  58. AND ($11::bool = false OR open = $12::bool)
  59. AND ($13::bool = false OR unlisted = $14::bool)
  60. LIMIT $15::int
  61. `
  62. type SelectStoriesParams struct {
  63. FilterID bool `json:"filter_id"`
  64. Ids []string `json:"ids"`
  65. FilterAuthor bool `json:"filter_author"`
  66. Author string `json:"author"`
  67. FilterEarlistFictionalDate bool `json:"filter_earlist_fictional_date"`
  68. EarliestFictionalDate time.Time `json:"earliest_fictional_date"`
  69. FilterLastestFictionalDate bool `json:"filter_lastest_fictional_date"`
  70. LatestFictionalDate time.Time `json:"latest_fictional_date"`
  71. FilterCategory bool `json:"filter_category"`
  72. Category string `json:"category"`
  73. FilterOpen bool `json:"filter_open"`
  74. Open bool `json:"open"`
  75. FilterUnlisted bool `json:"filter_unlisted"`
  76. Unlisted bool `json:"unlisted"`
  77. LimitSize int32 `json:"limit_size"`
  78. }
  79. func (q *Queries) SelectStories(ctx context.Context, arg SelectStoriesParams) ([]Story, error) {
  80. rows, err := q.db.QueryContext(ctx, selectStories,
  81. arg.FilterID,
  82. pq.Array(arg.Ids),
  83. arg.FilterAuthor,
  84. arg.Author,
  85. arg.FilterEarlistFictionalDate,
  86. arg.EarliestFictionalDate,
  87. arg.FilterLastestFictionalDate,
  88. arg.LatestFictionalDate,
  89. arg.FilterCategory,
  90. arg.Category,
  91. arg.FilterOpen,
  92. arg.Open,
  93. arg.FilterUnlisted,
  94. arg.Unlisted,
  95. arg.LimitSize,
  96. )
  97. if err != nil {
  98. return nil, err
  99. }
  100. defer rows.Close()
  101. items := []Story{}
  102. for rows.Next() {
  103. var i Story
  104. if err := rows.Scan(
  105. &i.ID,
  106. &i.Author,
  107. &i.Name,
  108. &i.Category,
  109. &i.Open,
  110. &i.Listed,
  111. &i.SortByFictionalDate,
  112. &i.CreatedDate,
  113. &i.FictionalDate,
  114. &i.UpdatedDate,
  115. ); err != nil {
  116. return nil, err
  117. }
  118. items = append(items, i)
  119. }
  120. if err := rows.Close(); err != nil {
  121. return nil, err
  122. }
  123. if err := rows.Err(); err != nil {
  124. return nil, err
  125. }
  126. return items, nil
  127. }
  128. const selectStory = `-- name: SelectStory :one
  129. SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story WHERE id = $1 LIMIT 1
  130. `
  131. func (q *Queries) SelectStory(ctx context.Context, id string) (Story, error) {
  132. row := q.db.QueryRowContext(ctx, selectStory, id)
  133. var i Story
  134. err := row.Scan(
  135. &i.ID,
  136. &i.Author,
  137. &i.Name,
  138. &i.Category,
  139. &i.Open,
  140. &i.Listed,
  141. &i.SortByFictionalDate,
  142. &i.CreatedDate,
  143. &i.FictionalDate,
  144. &i.UpdatedDate,
  145. )
  146. return i, err
  147. }
  148. const updateStory = `-- name: UpdateStory :exec
  149. UPDATE story
  150. SET name=$1,
  151. category=$2,
  152. author=$3,
  153. open=$4,
  154. listed=$5,
  155. fictional_date=$6,
  156. updated_date=$7,
  157. sort_by_fictional_date=$8
  158. WHERE id=$9
  159. `
  160. type UpdateStoryParams struct {
  161. Name string `json:"name"`
  162. Category string `json:"category"`
  163. Author string `json:"author"`
  164. Open bool `json:"open"`
  165. Listed bool `json:"listed"`
  166. FictionalDate time.Time `json:"fictional_date"`
  167. UpdatedDate time.Time `json:"updated_date"`
  168. SortByFictionalDate bool `json:"sort_by_fictional_date"`
  169. ID string `json:"id"`
  170. }
  171. func (q *Queries) UpdateStory(ctx context.Context, arg UpdateStoryParams) error {
  172. _, err := q.db.ExecContext(ctx, updateStory,
  173. arg.Name,
  174. arg.Category,
  175. arg.Author,
  176. arg.Open,
  177. arg.Listed,
  178. arg.FictionalDate,
  179. arg.UpdatedDate,
  180. arg.SortByFictionalDate,
  181. arg.ID,
  182. )
  183. return err
  184. }