query.sql 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* name: GetAuthor :one */
  2. SELECT * FROM authors
  3. WHERE author_id = ?;
  4. /* name: GetBook :one */
  5. SELECT * FROM books
  6. WHERE book_id = ?;
  7. /* name: DeleteBook :exec */
  8. DELETE FROM books
  9. WHERE book_id = ?;
  10. /* name: BooksByTitleYear :many */
  11. SELECT * FROM books
  12. WHERE title = ? AND yr = ?;
  13. /* name: BooksByTags :many */
  14. SELECT
  15. book_id,
  16. title,
  17. name,
  18. isbn,
  19. tag
  20. FROM books
  21. LEFT JOIN authors ON books.author_id = authors.author_id
  22. WHERE tag IN (sqlc.slice(tags));
  23. /* name: CreateAuthor :one */
  24. INSERT INTO authors (name) VALUES (?)
  25. RETURNING *;
  26. /* name: CreateBook :one */
  27. INSERT INTO books (
  28. author_id,
  29. isbn,
  30. book_type,
  31. title,
  32. yr,
  33. available,
  34. tag
  35. ) VALUES (
  36. ?,
  37. ?,
  38. ?,
  39. ?,
  40. ?,
  41. ?,
  42. ?
  43. )
  44. RETURNING *;
  45. /* name: UpdateBook :exec */
  46. UPDATE books
  47. SET title = ?1, tag = ?2
  48. WHERE book_id = ?3;
  49. /* name: UpdateBookISBN :exec */
  50. UPDATE books
  51. SET title = ?1, tag = ?2, isbn = ?4
  52. WHERE book_id = ?3;
  53. /* name: DeleteAuthorBeforeYear :exec */
  54. DELETE FROM books
  55. WHERE yr < ? AND author_id = ?;