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.

177 lines
4.5 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: chapters.sql
  3. package psqlcore
  4. import (
  5. "context"
  6. "time"
  7. )
  8. const deleteChapter = `-- name: DeleteChapter :exec
  9. DELETE FROM story_chapter WHERE id=$1
  10. `
  11. func (q *Queries) DeleteChapter(ctx context.Context, id string) error {
  12. _, err := q.db.ExecContext(ctx, deleteChapter, id)
  13. return err
  14. }
  15. const deleteChaptersByStoryID = `-- name: DeleteChaptersByStoryID :exec
  16. DELETE FROM story_chapter WHERE story_id=$1
  17. `
  18. func (q *Queries) DeleteChaptersByStoryID(ctx context.Context, storyID string) error {
  19. _, err := q.db.ExecContext(ctx, deleteChaptersByStoryID, storyID)
  20. return err
  21. }
  22. const insertChapter = `-- name: InsertChapter :exec
  23. INSERT INTO story_chapter (id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked)
  24. VALUES (
  25. $1::TEXT, $2::TEXT, $3::TEXT, $4::TEXT, $5::TEXT,
  26. $6::TIMESTAMP, $7::TIMESTAMP, $8::TIMESTAMP,
  27. $9::TEXT, $10::BOOLEAN
  28. )
  29. `
  30. type InsertChapterParams struct {
  31. ID string `json:"id"`
  32. StoryID string `json:"story_id"`
  33. Title string `json:"title"`
  34. Author string `json:"author"`
  35. Source string `json:"source"`
  36. CreatedDate time.Time `json:"created_date"`
  37. FictionalDate time.Time `json:"fictional_date"`
  38. EditedDate time.Time `json:"edited_date"`
  39. CommentMode string `json:"comment_mode"`
  40. CommentsLocked bool `json:"comments_locked"`
  41. }
  42. func (q *Queries) InsertChapter(ctx context.Context, arg InsertChapterParams) error {
  43. _, err := q.db.ExecContext(ctx, insertChapter,
  44. arg.ID,
  45. arg.StoryID,
  46. arg.Title,
  47. arg.Author,
  48. arg.Source,
  49. arg.CreatedDate,
  50. arg.FictionalDate,
  51. arg.EditedDate,
  52. arg.CommentMode,
  53. arg.CommentsLocked,
  54. )
  55. return err
  56. }
  57. const selectChapter = `-- name: SelectChapter :one
  58. SELECT id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked FROM story_chapter WHERE id=$1::TEXT LIMIT 1
  59. `
  60. func (q *Queries) SelectChapter(ctx context.Context, dollar_1 string) (StoryChapter, error) {
  61. row := q.db.QueryRowContext(ctx, selectChapter, dollar_1)
  62. var i StoryChapter
  63. err := row.Scan(
  64. &i.ID,
  65. &i.StoryID,
  66. &i.Title,
  67. &i.Author,
  68. &i.Source,
  69. &i.CreatedDate,
  70. &i.FictionalDate,
  71. &i.EditedDate,
  72. &i.CommentMode,
  73. &i.CommentsLocked,
  74. )
  75. return i, err
  76. }
  77. const selectChapters = `-- name: SelectChapters :many
  78. SELECT id, story_id, title, author, source, created_date, fictional_date, edited_date, comment_mode, comments_locked FROM story_chapter WHERE (sqlx.arg(story_id)::TEXT == '' OR story_id=$1::TEXT) ORDER BY created_date LIMIT $2::INT
  79. `
  80. type SelectChaptersParams struct {
  81. StoryID string `json:"story_id"`
  82. LimitSize int32 `json:"limit_size"`
  83. }
  84. func (q *Queries) SelectChapters(ctx context.Context, arg SelectChaptersParams) ([]StoryChapter, error) {
  85. rows, err := q.db.QueryContext(ctx, selectChapters, arg.StoryID, arg.LimitSize)
  86. if err != nil {
  87. return nil, err
  88. }
  89. defer rows.Close()
  90. items := []StoryChapter{}
  91. for rows.Next() {
  92. var i StoryChapter
  93. if err := rows.Scan(
  94. &i.ID,
  95. &i.StoryID,
  96. &i.Title,
  97. &i.Author,
  98. &i.Source,
  99. &i.CreatedDate,
  100. &i.FictionalDate,
  101. &i.EditedDate,
  102. &i.CommentMode,
  103. &i.CommentsLocked,
  104. ); err != nil {
  105. return nil, err
  106. }
  107. items = append(items, i)
  108. }
  109. if err := rows.Close(); err != nil {
  110. return nil, err
  111. }
  112. if err := rows.Err(); err != nil {
  113. return nil, err
  114. }
  115. return items, nil
  116. }
  117. const updateChapter = `-- name: UpdateChapter :exec
  118. UPDATE story_chapter
  119. SET title=$1,
  120. source=$2,
  121. fictional_date=$3,
  122. comment_mode=$4,
  123. comments_locked=$5
  124. WHERE id=$6
  125. `
  126. type UpdateChapterParams struct {
  127. Title string `json:"title"`
  128. Source string `json:"source"`
  129. FictionalDate time.Time `json:"fictional_date"`
  130. CommentMode string `json:"comment_mode"`
  131. CommentsLocked bool `json:"comments_locked"`
  132. ID string `json:"id"`
  133. }
  134. func (q *Queries) UpdateChapter(ctx context.Context, arg UpdateChapterParams) error {
  135. _, err := q.db.ExecContext(ctx, updateChapter,
  136. arg.Title,
  137. arg.Source,
  138. arg.FictionalDate,
  139. arg.CommentMode,
  140. arg.CommentsLocked,
  141. arg.ID,
  142. )
  143. return err
  144. }
  145. const updateChapterStoryID = `-- name: UpdateChapterStoryID :exec
  146. UPDATE story_chapter
  147. SET story_id=$1::TEXT
  148. WHERE id=$2
  149. `
  150. type UpdateChapterStoryIDParams struct {
  151. StoryID string `json:"story_id"`
  152. ID string `json:"id"`
  153. }
  154. func (q *Queries) UpdateChapterStoryID(ctx context.Context, arg UpdateChapterStoryIDParams) error {
  155. _, err := q.db.ExecContext(ctx, updateChapterStoryID, arg.StoryID, arg.ID)
  156. return err
  157. }