query.sql.go 4.8 KB

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