1
0

venue.sql.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.23.0
  4. // source: venue.sql
  5. package ondeck
  6. import (
  7. "context"
  8. "github.com/lib/pq"
  9. )
  10. const createVenue = `-- name: CreateVenue :one
  11. INSERT INTO venue (
  12. slug,
  13. name,
  14. city,
  15. created_at,
  16. spotify_playlist,
  17. status,
  18. statuses,
  19. tags
  20. ) VALUES (
  21. $1,
  22. $2,
  23. $3,
  24. NOW(),
  25. $4,
  26. $5,
  27. $6,
  28. $7
  29. ) RETURNING id
  30. `
  31. type CreateVenueParams struct {
  32. Slug string `json:"slug"`
  33. Name string `json:"name"`
  34. City string `json:"city"`
  35. SpotifyPlaylist string `json:"spotify_playlist"`
  36. Status Status `json:"status"`
  37. Statuses []Status `json:"statuses"`
  38. Tags []string `json:"tags"`
  39. }
  40. func (q *Queries) CreateVenue(ctx context.Context, arg CreateVenueParams) (int32, error) {
  41. row := q.queryRow(ctx, q.createVenueStmt, createVenue,
  42. arg.Slug,
  43. arg.Name,
  44. arg.City,
  45. arg.SpotifyPlaylist,
  46. arg.Status,
  47. pq.Array(arg.Statuses),
  48. pq.Array(arg.Tags),
  49. )
  50. var id int32
  51. err := row.Scan(&id)
  52. return id, err
  53. }
  54. const deleteVenue = `-- name: DeleteVenue :exec
  55. DELETE FROM venue
  56. WHERE slug = $1 AND slug = $1
  57. `
  58. func (q *Queries) DeleteVenue(ctx context.Context, slug string) error {
  59. _, err := q.exec(ctx, q.deleteVenueStmt, deleteVenue, slug)
  60. return err
  61. }
  62. const getVenue = `-- name: GetVenue :one
  63. SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
  64. FROM venue
  65. WHERE slug = $1 AND city = $2
  66. `
  67. type GetVenueParams struct {
  68. Slug string `json:"slug"`
  69. City string `json:"city"`
  70. }
  71. func (q *Queries) GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error) {
  72. row := q.queryRow(ctx, q.getVenueStmt, getVenue, arg.Slug, arg.City)
  73. var i Venue
  74. err := row.Scan(
  75. &i.ID,
  76. &i.Status,
  77. pq.Array(&i.Statuses),
  78. &i.Slug,
  79. &i.Name,
  80. &i.City,
  81. &i.SpotifyPlaylist,
  82. &i.SongkickID,
  83. pq.Array(&i.Tags),
  84. &i.CreatedAt,
  85. )
  86. return i, err
  87. }
  88. const listVenues = `-- name: ListVenues :many
  89. SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
  90. FROM venue
  91. WHERE city = $1
  92. ORDER BY name
  93. `
  94. func (q *Queries) ListVenues(ctx context.Context, city string) ([]Venue, error) {
  95. rows, err := q.query(ctx, q.listVenuesStmt, listVenues, city)
  96. if err != nil {
  97. return nil, err
  98. }
  99. defer rows.Close()
  100. var items []Venue
  101. for rows.Next() {
  102. var i Venue
  103. if err := rows.Scan(
  104. &i.ID,
  105. &i.Status,
  106. pq.Array(&i.Statuses),
  107. &i.Slug,
  108. &i.Name,
  109. &i.City,
  110. &i.SpotifyPlaylist,
  111. &i.SongkickID,
  112. pq.Array(&i.Tags),
  113. &i.CreatedAt,
  114. ); err != nil {
  115. return nil, err
  116. }
  117. items = append(items, i)
  118. }
  119. if err := rows.Close(); err != nil {
  120. return nil, err
  121. }
  122. if err := rows.Err(); err != nil {
  123. return nil, err
  124. }
  125. return items, nil
  126. }
  127. const updateVenueName = `-- name: UpdateVenueName :one
  128. UPDATE venue
  129. SET name = $2
  130. WHERE slug = $1
  131. RETURNING id
  132. `
  133. type UpdateVenueNameParams struct {
  134. Slug string `json:"slug"`
  135. Name string `json:"name"`
  136. }
  137. func (q *Queries) UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) (int32, error) {
  138. row := q.queryRow(ctx, q.updateVenueNameStmt, updateVenueName, arg.Slug, arg.Name)
  139. var id int32
  140. err := row.Scan(&id)
  141. return id, err
  142. }
  143. const venueCountByCity = `-- name: VenueCountByCity :many
  144. SELECT
  145. city,
  146. count(*)
  147. FROM venue
  148. GROUP BY 1
  149. ORDER BY 1
  150. `
  151. type VenueCountByCityRow struct {
  152. City string `json:"city"`
  153. Count int64 `json:"count"`
  154. }
  155. func (q *Queries) VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error) {
  156. rows, err := q.query(ctx, q.venueCountByCityStmt, venueCountByCity)
  157. if err != nil {
  158. return nil, err
  159. }
  160. defer rows.Close()
  161. var items []VenueCountByCityRow
  162. for rows.Next() {
  163. var i VenueCountByCityRow
  164. if err := rows.Scan(&i.City, &i.Count); err != nil {
  165. return nil, err
  166. }
  167. items = append(items, i)
  168. }
  169. if err := rows.Close(); err != nil {
  170. return nil, err
  171. }
  172. if err := rows.Err(); err != nil {
  173. return nil, err
  174. }
  175. return items, nil
  176. }