query.sql.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.27.0
  4. // source: query.sql
  5. package booktest
  6. import (
  7. "context"
  8. "github.com/jackc/pgx/v5/pgtype"
  9. )
  10. const booksByTags = `-- name: BooksByTags :many
  11. SELECT
  12. book_id,
  13. title,
  14. name,
  15. isbn,
  16. tags
  17. FROM books
  18. LEFT JOIN authors ON books.author_id = authors.author_id
  19. WHERE tags && $1::varchar[]
  20. `
  21. type BooksByTagsRow struct {
  22. BookID int32
  23. Title string
  24. Name pgtype.Text
  25. Isbn string
  26. Tags []string
  27. }
  28. func (q *Queries) BooksByTags(ctx context.Context, dollar_1 []string) ([]BooksByTagsRow, error) {
  29. rows, err := q.db.Query(ctx, booksByTags, dollar_1)
  30. if err != nil {
  31. return nil, err
  32. }
  33. defer rows.Close()
  34. var items []BooksByTagsRow
  35. for rows.Next() {
  36. var i BooksByTagsRow
  37. if err := rows.Scan(
  38. &i.BookID,
  39. &i.Title,
  40. &i.Name,
  41. &i.Isbn,
  42. &i.Tags,
  43. ); err != nil {
  44. return nil, err
  45. }
  46. items = append(items, i)
  47. }
  48. if err := rows.Err(); err != nil {
  49. return nil, err
  50. }
  51. return items, nil
  52. }
  53. const booksByTitleYear = `-- name: BooksByTitleYear :many
  54. SELECT book_id, author_id, isbn, book_type, title, year, available, tags FROM books
  55. WHERE title = $1 AND year = $2
  56. `
  57. type BooksByTitleYearParams struct {
  58. Title string
  59. Year int32
  60. }
  61. func (q *Queries) BooksByTitleYear(ctx context.Context, arg BooksByTitleYearParams) ([]Book, error) {
  62. rows, err := q.db.Query(ctx, booksByTitleYear, arg.Title, arg.Year)
  63. if err != nil {
  64. return nil, err
  65. }
  66. defer rows.Close()
  67. var items []Book
  68. for rows.Next() {
  69. var i Book
  70. if err := rows.Scan(
  71. &i.BookID,
  72. &i.AuthorID,
  73. &i.Isbn,
  74. &i.BookType,
  75. &i.Title,
  76. &i.Year,
  77. &i.Available,
  78. &i.Tags,
  79. ); err != nil {
  80. return nil, err
  81. }
  82. items = append(items, i)
  83. }
  84. if err := rows.Err(); err != nil {
  85. return nil, err
  86. }
  87. return items, nil
  88. }
  89. const createAuthor = `-- name: CreateAuthor :one
  90. INSERT INTO authors (name) VALUES ($1)
  91. RETURNING author_id, name
  92. `
  93. func (q *Queries) CreateAuthor(ctx context.Context, name string) (Author, error) {
  94. row := q.db.QueryRow(ctx, createAuthor, name)
  95. var i Author
  96. err := row.Scan(&i.AuthorID, &i.Name)
  97. return i, err
  98. }
  99. const createBook = `-- name: CreateBook :one
  100. INSERT INTO books (
  101. author_id,
  102. isbn,
  103. book_type,
  104. title,
  105. year,
  106. available,
  107. tags
  108. ) VALUES (
  109. $1,
  110. $2,
  111. $3,
  112. $4,
  113. $5,
  114. $6,
  115. $7
  116. )
  117. RETURNING book_id, author_id, isbn, book_type, title, year, available, tags
  118. `
  119. type CreateBookParams struct {
  120. AuthorID int32
  121. Isbn string
  122. BookType BookType
  123. Title string
  124. Year int32
  125. Available pgtype.Timestamptz
  126. Tags []string
  127. }
  128. func (q *Queries) CreateBook(ctx context.Context, arg CreateBookParams) (Book, error) {
  129. row := q.db.QueryRow(ctx, createBook,
  130. arg.AuthorID,
  131. arg.Isbn,
  132. arg.BookType,
  133. arg.Title,
  134. arg.Year,
  135. arg.Available,
  136. arg.Tags,
  137. )
  138. var i Book
  139. err := row.Scan(
  140. &i.BookID,
  141. &i.AuthorID,
  142. &i.Isbn,
  143. &i.BookType,
  144. &i.Title,
  145. &i.Year,
  146. &i.Available,
  147. &i.Tags,
  148. )
  149. return i, err
  150. }
  151. const deleteBook = `-- name: DeleteBook :exec
  152. DELETE FROM books
  153. WHERE book_id = $1
  154. `
  155. func (q *Queries) DeleteBook(ctx context.Context, bookID int32) error {
  156. _, err := q.db.Exec(ctx, deleteBook, bookID)
  157. return err
  158. }
  159. const getAuthor = `-- name: GetAuthor :one
  160. SELECT author_id, name FROM authors
  161. WHERE author_id = $1
  162. `
  163. func (q *Queries) GetAuthor(ctx context.Context, authorID int32) (Author, error) {
  164. row := q.db.QueryRow(ctx, getAuthor, authorID)
  165. var i Author
  166. err := row.Scan(&i.AuthorID, &i.Name)
  167. return i, err
  168. }
  169. const getBook = `-- name: GetBook :one
  170. SELECT book_id, author_id, isbn, book_type, title, year, available, tags FROM books
  171. WHERE book_id = $1
  172. `
  173. func (q *Queries) GetBook(ctx context.Context, bookID int32) (Book, error) {
  174. row := q.db.QueryRow(ctx, getBook, bookID)
  175. var i Book
  176. err := row.Scan(
  177. &i.BookID,
  178. &i.AuthorID,
  179. &i.Isbn,
  180. &i.BookType,
  181. &i.Title,
  182. &i.Year,
  183. &i.Available,
  184. &i.Tags,
  185. )
  186. return i, err
  187. }
  188. const sayHello = `-- name: SayHello :one
  189. select say_hello from say_hello($1)
  190. `
  191. func (q *Queries) SayHello(ctx context.Context, s string) (pgtype.Text, error) {
  192. row := q.db.QueryRow(ctx, sayHello, s)
  193. var say_hello pgtype.Text
  194. err := row.Scan(&say_hello)
  195. return say_hello, err
  196. }
  197. const updateBook = `-- name: UpdateBook :exec
  198. UPDATE books
  199. SET title = $1, tags = $2
  200. WHERE book_id = $3
  201. `
  202. type UpdateBookParams struct {
  203. Title string
  204. Tags []string
  205. BookID int32
  206. }
  207. func (q *Queries) UpdateBook(ctx context.Context, arg UpdateBookParams) error {
  208. _, err := q.db.Exec(ctx, updateBook, arg.Title, arg.Tags, arg.BookID)
  209. return err
  210. }
  211. const updateBookISBN = `-- name: UpdateBookISBN :exec
  212. UPDATE books
  213. SET title = $1, tags = $2, isbn = $4
  214. WHERE book_id = $3
  215. `
  216. type UpdateBookISBNParams struct {
  217. Title string
  218. Tags []string
  219. BookID int32
  220. Isbn string
  221. }
  222. func (q *Queries) UpdateBookISBN(ctx context.Context, arg UpdateBookISBNParams) error {
  223. _, err := q.db.Exec(ctx, updateBookISBN,
  224. arg.Title,
  225. arg.Tags,
  226. arg.BookID,
  227. arg.Isbn,
  228. )
  229. return err
  230. }