query.sql.go 1.5 KB

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