query.sql 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. -- name: GetAuthor :one
  2. SELECT * FROM authors
  3. WHERE author_id = $1;
  4. -- name: GetBook :one
  5. SELECT * FROM books
  6. WHERE book_id = $1;
  7. -- name: DeleteBook :exec
  8. DELETE FROM books
  9. WHERE book_id = $1;
  10. -- name: BooksByTitleYear :many
  11. SELECT * FROM books
  12. WHERE title = $1 AND year = $2;
  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 && $1::varchar[];
  23. -- name: CreateAuthor :one
  24. INSERT INTO authors (name) VALUES ($1)
  25. RETURNING *;
  26. -- name: CreateBook :one
  27. INSERT INTO books (
  28. author_id,
  29. isbn,
  30. book_type,
  31. title,
  32. year,
  33. available,
  34. tags
  35. ) VALUES (
  36. $1,
  37. $2,
  38. $3,
  39. $4,
  40. $5,
  41. $6,
  42. $7
  43. )
  44. RETURNING *;
  45. -- name: UpdateBook :exec
  46. UPDATE books
  47. SET title = $1, tags = $2
  48. WHERE book_id = $3;
  49. -- name: UpdateBookISBN :exec
  50. UPDATE books
  51. SET title = $1, tags = $2, isbn = $4
  52. WHERE book_id = $3;
  53. -- name: SayHello :one
  54. select * from say_hello($1);