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.

113 lines
3.1 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 selectStories = `-- name: SelectStories :many
  10. SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story
  11. WHERE ($1::bool = false OR id = ANY($2::text[]))
  12. AND ($3::bool = false OR name = $4::text)
  13. AND ($5::bool = false OR fictional_date >= $6::timestamp)
  14. AND ($7::bool = false OR fictional_date <= $8::timestamp)
  15. AND ($9::bool = false OR category = $10::text)
  16. AND ($11::bool = false OR open = $12::bool)
  17. AND ($13::bool = false OR unlisted = $14::bool)
  18. LIMIT $15::int
  19. `
  20. type SelectStoriesParams struct {
  21. FilterID bool `json:"filter_id"`
  22. Ids []string `json:"ids"`
  23. FilterAuthor bool `json:"filter_author"`
  24. Author string `json:"author"`
  25. FilterEarlistFictionalDate bool `json:"filter_earlist_fictional_date"`
  26. EarliestFictionalDate time.Time `json:"earliest_fictional_date"`
  27. FilterLastestFictionalDate bool `json:"filter_lastest_fictional_date"`
  28. LatestFictionalDate time.Time `json:"latest_fictional_date"`
  29. FilterCategory bool `json:"filter_category"`
  30. Category string `json:"category"`
  31. FilterOpen bool `json:"filter_open"`
  32. Open bool `json:"open"`
  33. FilterUnlisted bool `json:"filter_unlisted"`
  34. Unlisted bool `json:"unlisted"`
  35. LimitSize int32 `json:"limit_size"`
  36. }
  37. func (q *Queries) SelectStories(ctx context.Context, arg SelectStoriesParams) ([]Story, error) {
  38. rows, err := q.db.QueryContext(ctx, selectStories,
  39. arg.FilterID,
  40. pq.Array(arg.Ids),
  41. arg.FilterAuthor,
  42. arg.Author,
  43. arg.FilterEarlistFictionalDate,
  44. arg.EarliestFictionalDate,
  45. arg.FilterLastestFictionalDate,
  46. arg.LatestFictionalDate,
  47. arg.FilterCategory,
  48. arg.Category,
  49. arg.FilterOpen,
  50. arg.Open,
  51. arg.FilterUnlisted,
  52. arg.Unlisted,
  53. arg.LimitSize,
  54. )
  55. if err != nil {
  56. return nil, err
  57. }
  58. defer rows.Close()
  59. items := []Story{}
  60. for rows.Next() {
  61. var i Story
  62. if err := rows.Scan(
  63. &i.ID,
  64. &i.Author,
  65. &i.Name,
  66. &i.Category,
  67. &i.Open,
  68. &i.Listed,
  69. &i.SortByFictionalDate,
  70. &i.CreatedDate,
  71. &i.FictionalDate,
  72. &i.UpdatedDate,
  73. ); err != nil {
  74. return nil, err
  75. }
  76. items = append(items, i)
  77. }
  78. if err := rows.Close(); err != nil {
  79. return nil, err
  80. }
  81. if err := rows.Err(); err != nil {
  82. return nil, err
  83. }
  84. return items, nil
  85. }
  86. const selectStory = `-- name: SelectStory :one
  87. SELECT id, author, name, category, open, listed, sort_by_fictional_date, created_date, fictional_date, updated_date FROM story WHERE id = $1 LIMIT 1
  88. `
  89. func (q *Queries) SelectStory(ctx context.Context, id string) (Story, error) {
  90. row := q.db.QueryRowContext(ctx, selectStory, id)
  91. var i Story
  92. err := row.Scan(
  93. &i.ID,
  94. &i.Author,
  95. &i.Name,
  96. &i.Category,
  97. &i.Open,
  98. &i.Listed,
  99. &i.SortByFictionalDate,
  100. &i.CreatedDate,
  101. &i.FictionalDate,
  102. &i.UpdatedDate,
  103. )
  104. return i, err
  105. }