1
0

db.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.23.0
  4. package ondeck
  5. import (
  6. "context"
  7. "database/sql"
  8. "fmt"
  9. )
  10. type DBTX interface {
  11. ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
  12. PrepareContext(context.Context, string) (*sql.Stmt, error)
  13. QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
  14. QueryRowContext(context.Context, string, ...interface{}) *sql.Row
  15. }
  16. func New(db DBTX) *Queries {
  17. return &Queries{db: db}
  18. }
  19. func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
  20. q := Queries{db: db}
  21. var err error
  22. if q.createCityStmt, err = db.PrepareContext(ctx, createCity); err != nil {
  23. return nil, fmt.Errorf("error preparing query CreateCity: %w", err)
  24. }
  25. if q.createVenueStmt, err = db.PrepareContext(ctx, createVenue); err != nil {
  26. return nil, fmt.Errorf("error preparing query CreateVenue: %w", err)
  27. }
  28. if q.deleteVenueStmt, err = db.PrepareContext(ctx, deleteVenue); err != nil {
  29. return nil, fmt.Errorf("error preparing query DeleteVenue: %w", err)
  30. }
  31. if q.getCityStmt, err = db.PrepareContext(ctx, getCity); err != nil {
  32. return nil, fmt.Errorf("error preparing query GetCity: %w", err)
  33. }
  34. if q.getVenueStmt, err = db.PrepareContext(ctx, getVenue); err != nil {
  35. return nil, fmt.Errorf("error preparing query GetVenue: %w", err)
  36. }
  37. if q.listCitiesStmt, err = db.PrepareContext(ctx, listCities); err != nil {
  38. return nil, fmt.Errorf("error preparing query ListCities: %w", err)
  39. }
  40. if q.listVenuesStmt, err = db.PrepareContext(ctx, listVenues); err != nil {
  41. return nil, fmt.Errorf("error preparing query ListVenues: %w", err)
  42. }
  43. if q.updateCityNameStmt, err = db.PrepareContext(ctx, updateCityName); err != nil {
  44. return nil, fmt.Errorf("error preparing query UpdateCityName: %w", err)
  45. }
  46. if q.updateVenueNameStmt, err = db.PrepareContext(ctx, updateVenueName); err != nil {
  47. return nil, fmt.Errorf("error preparing query UpdateVenueName: %w", err)
  48. }
  49. if q.venueCountByCityStmt, err = db.PrepareContext(ctx, venueCountByCity); err != nil {
  50. return nil, fmt.Errorf("error preparing query VenueCountByCity: %w", err)
  51. }
  52. return &q, nil
  53. }
  54. func (q *Queries) Close() error {
  55. var err error
  56. if q.createCityStmt != nil {
  57. if cerr := q.createCityStmt.Close(); cerr != nil {
  58. err = fmt.Errorf("error closing createCityStmt: %w", cerr)
  59. }
  60. }
  61. if q.createVenueStmt != nil {
  62. if cerr := q.createVenueStmt.Close(); cerr != nil {
  63. err = fmt.Errorf("error closing createVenueStmt: %w", cerr)
  64. }
  65. }
  66. if q.deleteVenueStmt != nil {
  67. if cerr := q.deleteVenueStmt.Close(); cerr != nil {
  68. err = fmt.Errorf("error closing deleteVenueStmt: %w", cerr)
  69. }
  70. }
  71. if q.getCityStmt != nil {
  72. if cerr := q.getCityStmt.Close(); cerr != nil {
  73. err = fmt.Errorf("error closing getCityStmt: %w", cerr)
  74. }
  75. }
  76. if q.getVenueStmt != nil {
  77. if cerr := q.getVenueStmt.Close(); cerr != nil {
  78. err = fmt.Errorf("error closing getVenueStmt: %w", cerr)
  79. }
  80. }
  81. if q.listCitiesStmt != nil {
  82. if cerr := q.listCitiesStmt.Close(); cerr != nil {
  83. err = fmt.Errorf("error closing listCitiesStmt: %w", cerr)
  84. }
  85. }
  86. if q.listVenuesStmt != nil {
  87. if cerr := q.listVenuesStmt.Close(); cerr != nil {
  88. err = fmt.Errorf("error closing listVenuesStmt: %w", cerr)
  89. }
  90. }
  91. if q.updateCityNameStmt != nil {
  92. if cerr := q.updateCityNameStmt.Close(); cerr != nil {
  93. err = fmt.Errorf("error closing updateCityNameStmt: %w", cerr)
  94. }
  95. }
  96. if q.updateVenueNameStmt != nil {
  97. if cerr := q.updateVenueNameStmt.Close(); cerr != nil {
  98. err = fmt.Errorf("error closing updateVenueNameStmt: %w", cerr)
  99. }
  100. }
  101. if q.venueCountByCityStmt != nil {
  102. if cerr := q.venueCountByCityStmt.Close(); cerr != nil {
  103. err = fmt.Errorf("error closing venueCountByCityStmt: %w", cerr)
  104. }
  105. }
  106. return err
  107. }
  108. func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
  109. switch {
  110. case stmt != nil && q.tx != nil:
  111. return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
  112. case stmt != nil:
  113. return stmt.ExecContext(ctx, args...)
  114. default:
  115. return q.db.ExecContext(ctx, query, args...)
  116. }
  117. }
  118. func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
  119. switch {
  120. case stmt != nil && q.tx != nil:
  121. return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
  122. case stmt != nil:
  123. return stmt.QueryContext(ctx, args...)
  124. default:
  125. return q.db.QueryContext(ctx, query, args...)
  126. }
  127. }
  128. func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
  129. switch {
  130. case stmt != nil && q.tx != nil:
  131. return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
  132. case stmt != nil:
  133. return stmt.QueryRowContext(ctx, args...)
  134. default:
  135. return q.db.QueryRowContext(ctx, query, args...)
  136. }
  137. }
  138. type Queries struct {
  139. db DBTX
  140. tx *sql.Tx
  141. createCityStmt *sql.Stmt
  142. createVenueStmt *sql.Stmt
  143. deleteVenueStmt *sql.Stmt
  144. getCityStmt *sql.Stmt
  145. getVenueStmt *sql.Stmt
  146. listCitiesStmt *sql.Stmt
  147. listVenuesStmt *sql.Stmt
  148. updateCityNameStmt *sql.Stmt
  149. updateVenueNameStmt *sql.Stmt
  150. venueCountByCityStmt *sql.Stmt
  151. }
  152. func (q *Queries) WithTx(tx *sql.Tx) *Queries {
  153. return &Queries{
  154. db: tx,
  155. tx: tx,
  156. createCityStmt: q.createCityStmt,
  157. createVenueStmt: q.createVenueStmt,
  158. deleteVenueStmt: q.deleteVenueStmt,
  159. getCityStmt: q.getCityStmt,
  160. getVenueStmt: q.getVenueStmt,
  161. listCitiesStmt: q.listCitiesStmt,
  162. listVenuesStmt: q.listVenuesStmt,
  163. updateCityNameStmt: q.updateCityNameStmt,
  164. updateVenueNameStmt: q.updateVenueNameStmt,
  165. venueCountByCityStmt: q.venueCountByCityStmt,
  166. }
  167. }