1
0

query.sql.go 1.6 KB

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