query.sql.go 1.6 KB

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