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.

201 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. ORDER BY updated_date
  61. LIMIT $15::int
  62. `
  63. type SelectStoriesParams struct {
  64. FilterID bool `json:"filter_id"`
  65. Ids []string `json:"ids"`
  66. FilterAuthor bool `json:"filter_author"`
  67. Author string `json:"author"`
  68. FilterEarlistFictionalDate bool `json:"filter_earlist_fictional_date"`
  69. EarliestFictionalDate time.Time `json:"earliest_fictional_date"`
  70. FilterLastestFictionalDate bool `json:"filter_lastest_fictional_date"`
  71. LatestFictionalDate time.Time `json:"latest_fictional_date"`
  72. FilterCategory bool `json:"filter_category"`
  73. Category string `json:"category"`
  74. FilterOpen bool `json:"filter_open"`
  75. Open bool `json:"open"`
  76. FilterUnlisted bool `json:"filter_unlisted"`
  77. Unlisted bool `json:"unlisted"`
  78. LimitSize int32 `json:"limit_size"`
  79. }
  80. func (q *Queries) SelectStories(ctx context.Context, arg SelectStoriesParams) ([]Story, error) {
  81. rows, err := q.db.QueryContext(ctx, selectStories,
  82. arg.FilterID,
  83. pq.Array(arg.Ids),
  84. arg.FilterAuthor,
  85. arg.Author,
  86. arg.FilterEarlistFictionalDate,
  87. arg.EarliestFictionalDate,
  88. arg.FilterLastestFictionalDate,
  89. arg.LatestFictionalDate,
  90. arg.FilterCategory,
  91. arg.Category,
  92. arg.FilterOpen,
  93. arg.Open,
  94. arg.FilterUnlisted,
  95. arg.Unlisted,
  96. arg.LimitSize,
  97. )
  98. if err != nil {
  99. return nil, err
  100. }
  101. defer rows.Close()
  102. items := []Story{}
  103. for rows.Next() {
  104. var i Story
  105. if err := rows.Scan(
  106. &i.ID,
  107. &i.Author,
  108. &i.Name,
  109. &i.Category,
  110. &i.Open,
  111. &i.Listed,
  112. &i.SortByFictionalDate,
  113. &i.CreatedDate,
  114. &i.FictionalDate,
  115. &i.UpdatedDate,
  116. ); err != nil {
  117. return nil, err
  118. }
  119. items = append(items, i)
  120. }
  121. if err := rows.Close(); err != nil {
  122. return nil, err
  123. }
  124. if err := rows.Err(); err != nil {
  125. return nil, err
  126. }
  127. return items, nil
  128. }
  129. const selectStory = `-- name: SelectStory :one
  130. SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story WHERE id = $1 LIMIT 1
  131. `
  132. func (q *Queries) SelectStory(ctx context.Context, id string) (Story, error) {
  133. row := q.db.QueryRowContext(ctx, selectStory, id)
  134. var i Story
  135. err := row.Scan(
  136. &i.ID,
  137. &i.Author,
  138. &i.Name,
  139. &i.Category,
  140. &i.Open,
  141. &i.Listed,
  142. &i.SortByFictionalDate,
  143. &i.CreatedDate,
  144. &i.FictionalDate,
  145. &i.UpdatedDate,
  146. )
  147. return i, err
  148. }
  149. const updateStory = `-- name: UpdateStory :exec
  150. UPDATE story
  151. SET name=$1,
  152. category=$2,
  153. author=$3,
  154. open=$4,
  155. listed=$5,
  156. fictional_date=$6,
  157. updated_date=$7,
  158. sort_by_fictional_date=$8
  159. WHERE id=$9
  160. `
  161. type UpdateStoryParams struct {
  162. Name string `json:"name"`
  163. Category string `json:"category"`
  164. Author string `json:"author"`
  165. Open bool `json:"open"`
  166. Listed bool `json:"listed"`
  167. FictionalDate time.Time `json:"fictional_date"`
  168. UpdatedDate time.Time `json:"updated_date"`
  169. SortByFictionalDate bool `json:"sort_by_fictional_date"`
  170. ID string `json:"id"`
  171. }
  172. func (q *Queries) UpdateStory(ctx context.Context, arg UpdateStoryParams) error {
  173. _, err := q.db.ExecContext(ctx, updateStory,
  174. arg.Name,
  175. arg.Category,
  176. arg.Author,
  177. arg.Open,
  178. arg.Listed,
  179. arg.FictionalDate,
  180. arg.UpdatedDate,
  181. arg.SortByFictionalDate,
  182. arg.ID,
  183. )
  184. return err
  185. }