1
0

query.sql.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // source: query.sql
  3. package authors
  4. import (
  5. "context"
  6. "database/sql"
  7. )
  8. const createAuthor = `-- name: CreateAuthor :one
  9. INSERT INTO authors (
  10. name, bio
  11. ) VALUES (
  12. $1, $2
  13. )
  14. RETURNING id, name, bio
  15. `
  16. type CreateAuthorParams struct {
  17. Name string
  18. Bio sql.NullString
  19. }
  20. func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) {
  21. row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio)
  22. var i Author
  23. err := row.Scan(&i.ID, &i.Name, &i.Bio)
  24. return i, err
  25. }
  26. const deleteAuthor = `-- name: DeleteAuthor :exec
  27. DELETE FROM authors
  28. WHERE id = $1
  29. `
  30. func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
  31. _, err := q.db.ExecContext(ctx, deleteAuthor, id)
  32. return err
  33. }
  34. const getAuthor = `-- name: GetAuthor :one
  35. SELECT id, name, bio FROM authors
  36. WHERE id = $1 LIMIT 1
  37. `
  38. func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
  39. row := q.db.QueryRowContext(ctx, getAuthor, id)
  40. var i Author
  41. err := row.Scan(&i.ID, &i.Name, &i.Bio)
  42. return i, err
  43. }
  44. const listAuthors = `-- name: ListAuthors :many
  45. SELECT id, name, bio FROM authors
  46. ORDER BY name
  47. `
  48. func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
  49. rows, err := q.db.QueryContext(ctx, listAuthors)
  50. if err != nil {
  51. return nil, err
  52. }
  53. defer rows.Close()
  54. var items []Author
  55. for rows.Next() {
  56. var i Author
  57. if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil {
  58. return nil, err
  59. }
  60. items = append(items, i)
  61. }
  62. if err := rows.Close(); err != nil {
  63. return nil, err
  64. }
  65. if err := rows.Err(); err != nil {
  66. return nil, err
  67. }
  68. return items, nil
  69. }