query.sql 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. tags
  20. FROM books
  21. LEFT JOIN authors ON books.author_id = authors.author_id
  22. WHERE tags = ?;
  23. /* name: CreateAuthor :execresult */
  24. INSERT INTO authors (name) VALUES (?);
  25. /* name: CreateBook :execresult */
  26. INSERT INTO books (
  27. author_id,
  28. isbn,
  29. book_type,
  30. title,
  31. yr,
  32. available,
  33. tags
  34. ) VALUES (
  35. ?,
  36. ?,
  37. ?,
  38. ?,
  39. ?,
  40. ?,
  41. ?
  42. );
  43. /* name: UpdateBook :exec */
  44. UPDATE books
  45. SET title = ?, tags = ?
  46. WHERE book_id = ?;
  47. /* name: UpdateBookISBN :exec */
  48. UPDATE books
  49. SET title = ?, tags = ?, isbn = ?
  50. WHERE book_id = ?;
  51. /* name: DeleteAuthorBeforeYear :exec */
  52. DELETE FROM books
  53. WHERE yr < ? AND author_id = ?;
  54. -- WHERE yr < sqlc.arg(min_publish_year) AND author_id = ?;