mirror of https://github.com/rocboss/paopao-ce
parent
c30cdf720b
commit
365841c535
@ -0,0 +1,3 @@
|
||||
package ce
|
||||
|
||||
//go:generate sqlc generate -x
|
@ -0,0 +1,88 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: city.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createCity = `-- name: CreateCity :exec
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
?,
|
||||
?
|
||||
)
|
||||
`
|
||||
|
||||
type CreateCityParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCity(ctx context.Context, arg CreateCityParams) error {
|
||||
_, err := q.exec(ctx, q.createCityStmt, createCity, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCity = `-- name: GetCity :one
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetCity(ctx context.Context, slug string) (City, error) {
|
||||
row := q.queryRow(ctx, q.getCityStmt, getCity, slug)
|
||||
var i City
|
||||
err := row.Scan(&i.Slug, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCities = `-- name: ListCities :many
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListCities(ctx context.Context) ([]City, error) {
|
||||
rows, err := q.query(ctx, q.listCitiesStmt, listCities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []City
|
||||
for rows.Next() {
|
||||
var i City
|
||||
if err := rows.Scan(&i.Slug, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateCityName = `-- name: UpdateCityName :exec
|
||||
UPDATE city
|
||||
SET name = ?
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
type UpdateCityNameParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error {
|
||||
_, err := q.exec(ctx, q.updateCityNameStmt, updateCityName, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
q := Queries{db: db}
|
||||
var err error
|
||||
if q.createCityStmt, err = db.PrepareContext(ctx, createCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query CreateCity: %w", err)
|
||||
}
|
||||
if q.createVenueStmt, err = db.PrepareContext(ctx, createVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query CreateVenue: %w", err)
|
||||
}
|
||||
if q.deleteVenueStmt, err = db.PrepareContext(ctx, deleteVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query DeleteVenue: %w", err)
|
||||
}
|
||||
if q.getCityStmt, err = db.PrepareContext(ctx, getCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query GetCity: %w", err)
|
||||
}
|
||||
if q.getVenueStmt, err = db.PrepareContext(ctx, getVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query GetVenue: %w", err)
|
||||
}
|
||||
if q.listCitiesStmt, err = db.PrepareContext(ctx, listCities); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListCities: %w", err)
|
||||
}
|
||||
if q.listVenuesStmt, err = db.PrepareContext(ctx, listVenues); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListVenues: %w", err)
|
||||
}
|
||||
if q.updateCityNameStmt, err = db.PrepareContext(ctx, updateCityName); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query UpdateCityName: %w", err)
|
||||
}
|
||||
if q.updateVenueNameStmt, err = db.PrepareContext(ctx, updateVenueName); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query UpdateVenueName: %w", err)
|
||||
}
|
||||
if q.venueCountByCityStmt, err = db.PrepareContext(ctx, venueCountByCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query VenueCountByCity: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
func (q *Queries) Close() error {
|
||||
var err error
|
||||
if q.createCityStmt != nil {
|
||||
if cerr := q.createCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing createCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.createVenueStmt != nil {
|
||||
if cerr := q.createVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing createVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.deleteVenueStmt != nil {
|
||||
if cerr := q.deleteVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing deleteVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.getCityStmt != nil {
|
||||
if cerr := q.getCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing getCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.getVenueStmt != nil {
|
||||
if cerr := q.getVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing getVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listCitiesStmt != nil {
|
||||
if cerr := q.listCitiesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listCitiesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listVenuesStmt != nil {
|
||||
if cerr := q.listVenuesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listVenuesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.updateCityNameStmt != nil {
|
||||
if cerr := q.updateCityNameStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing updateCityNameStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.updateVenueNameStmt != nil {
|
||||
if cerr := q.updateVenueNameStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing updateVenueNameStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.venueCountByCityStmt != nil {
|
||||
if cerr := q.venueCountByCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing venueCountByCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.ExecContext(ctx, args...)
|
||||
default:
|
||||
return q.db.ExecContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryRowContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryRowContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
tx *sql.Tx
|
||||
createCityStmt *sql.Stmt
|
||||
createVenueStmt *sql.Stmt
|
||||
deleteVenueStmt *sql.Stmt
|
||||
getCityStmt *sql.Stmt
|
||||
getVenueStmt *sql.Stmt
|
||||
listCitiesStmt *sql.Stmt
|
||||
listVenuesStmt *sql.Stmt
|
||||
updateCityNameStmt *sql.Stmt
|
||||
updateVenueNameStmt *sql.Stmt
|
||||
venueCountByCityStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
tx: tx,
|
||||
createCityStmt: q.createCityStmt,
|
||||
createVenueStmt: q.createVenueStmt,
|
||||
deleteVenueStmt: q.deleteVenueStmt,
|
||||
getCityStmt: q.getCityStmt,
|
||||
getVenueStmt: q.getVenueStmt,
|
||||
listCitiesStmt: q.listCitiesStmt,
|
||||
listVenuesStmt: q.listVenuesStmt,
|
||||
updateCityNameStmt: q.updateCityNameStmt,
|
||||
updateVenueNameStmt: q.updateVenueNameStmt,
|
||||
venueCountByCityStmt: q.venueCountByCityStmt,
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type VenuesStatus string
|
||||
|
||||
const (
|
||||
VenuesStatusOpen VenuesStatus = "open"
|
||||
VenuesStatusClosed VenuesStatus = "closed"
|
||||
)
|
||||
|
||||
func (e *VenuesStatus) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = VenuesStatus(s)
|
||||
case string:
|
||||
*e = VenuesStatus(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for VenuesStatus: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullVenuesStatus struct {
|
||||
VenuesStatus VenuesStatus
|
||||
Valid bool // Valid is true if VenuesStatus is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullVenuesStatus) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.VenuesStatus, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.VenuesStatus.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullVenuesStatus) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.VenuesStatus), nil
|
||||
}
|
||||
|
||||
type City struct {
|
||||
Slug string
|
||||
Name string
|
||||
}
|
||||
|
||||
// Venues are places where muisc happens
|
||||
type Venue struct {
|
||||
ID int64
|
||||
// Venues can be either open or closed
|
||||
Status VenuesStatus
|
||||
Statuses sql.NullString
|
||||
// This value appears in public URLs
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
SongkickID sql.NullString
|
||||
Tags sql.NullString
|
||||
CreatedAt time.Time
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
CreateCity(ctx context.Context, arg CreateCityParams) error
|
||||
CreateVenue(ctx context.Context, arg CreateVenueParams) (sql.Result, error)
|
||||
DeleteVenue(ctx context.Context, arg DeleteVenueParams) error
|
||||
GetCity(ctx context.Context, slug string) (City, error)
|
||||
GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error)
|
||||
ListCities(ctx context.Context) ([]City, error)
|
||||
ListVenues(ctx context.Context, city string) ([]Venue, error)
|
||||
UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error
|
||||
UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) error
|
||||
VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
@ -0,0 +1,23 @@
|
||||
/* name: ListCities :many */
|
||||
SELECT *
|
||||
FROM city
|
||||
ORDER BY name;
|
||||
|
||||
/* name: GetCity :one */
|
||||
SELECT *
|
||||
FROM city
|
||||
WHERE slug = ?;
|
||||
|
||||
/* name: CreateCity :exec */
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
?,
|
||||
?
|
||||
);
|
||||
|
||||
/* name: UpdateCityName :exec */
|
||||
UPDATE city
|
||||
SET name = ?
|
||||
WHERE slug = ?;
|
@ -0,0 +1,48 @@
|
||||
/* name: ListVenues :many */
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE city = ?
|
||||
ORDER BY name;
|
||||
|
||||
/* name: DeleteVenue :exec */
|
||||
DELETE FROM venue
|
||||
WHERE slug = ? AND slug = ?;
|
||||
|
||||
/* name: GetVenue :one */
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE slug = ? AND city = ?;
|
||||
|
||||
/* name: CreateVenue :execresult */
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
);
|
||||
|
||||
/* name: UpdateVenueName :exec */
|
||||
UPDATE venue
|
||||
SET name = ?
|
||||
WHERE slug = ?;
|
||||
|
||||
/* name: VenueCountByCity :many */
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1;
|
@ -0,0 +1,4 @@
|
||||
CREATE TABLE city (
|
||||
slug varchar(255) PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
CREATE TABLE venues (
|
||||
id SERIAL primary key,
|
||||
dropped text,
|
||||
status ENUM('open', 'closed') not null COMMENT 'Venues can be either open or closed',
|
||||
statuses text, -- status[],
|
||||
slug text not null COMMENT 'This value appears in public URLs',
|
||||
name varchar(255) not null,
|
||||
city text not null references city(slug),
|
||||
spotify_playlist varchar(255) not null,
|
||||
songkick_id text,
|
||||
tags text -- text[]
|
||||
) COMMENT='Venues are places where muisc happens';
|
@ -0,0 +1,3 @@
|
||||
ALTER TABLE venues RENAME TO venue;
|
||||
ALTER TABLE venue ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT NOW();
|
||||
ALTER TABLE venue DROP COLUMN dropped;
|
@ -0,0 +1,193 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: venue.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createVenue = `-- name: CreateVenue :execresult
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)
|
||||
`
|
||||
|
||||
type CreateVenueParams struct {
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
Status VenuesStatus
|
||||
Statuses sql.NullString
|
||||
Tags sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateVenue(ctx context.Context, arg CreateVenueParams) (sql.Result, error) {
|
||||
return q.exec(ctx, q.createVenueStmt, createVenue,
|
||||
arg.Slug,
|
||||
arg.Name,
|
||||
arg.City,
|
||||
arg.SpotifyPlaylist,
|
||||
arg.Status,
|
||||
arg.Statuses,
|
||||
arg.Tags,
|
||||
)
|
||||
}
|
||||
|
||||
const deleteVenue = `-- name: DeleteVenue :exec
|
||||
DELETE FROM venue
|
||||
WHERE slug = ? AND slug = ?
|
||||
`
|
||||
|
||||
type DeleteVenueParams struct {
|
||||
Slug string
|
||||
Slug_2 string
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteVenue(ctx context.Context, arg DeleteVenueParams) error {
|
||||
_, err := q.exec(ctx, q.deleteVenueStmt, deleteVenue, arg.Slug, arg.Slug_2)
|
||||
return err
|
||||
}
|
||||
|
||||
const getVenue = `-- name: GetVenue :one
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE slug = ? AND city = ?
|
||||
`
|
||||
|
||||
type GetVenueParams struct {
|
||||
Slug string
|
||||
City string
|
||||
}
|
||||
|
||||
func (q *Queries) GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error) {
|
||||
row := q.queryRow(ctx, q.getVenueStmt, getVenue, arg.Slug, arg.City)
|
||||
var i Venue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listVenues = `-- name: ListVenues :many
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE city = ?
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListVenues(ctx context.Context, city string) ([]Venue, error) {
|
||||
rows, err := q.query(ctx, q.listVenuesStmt, listVenues, city)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Venue
|
||||
for rows.Next() {
|
||||
var i Venue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateVenueName = `-- name: UpdateVenueName :exec
|
||||
UPDATE venue
|
||||
SET name = ?
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
type UpdateVenueNameParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) error {
|
||||
_, err := q.exec(ctx, q.updateVenueNameStmt, updateVenueName, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
||||
|
||||
const venueCountByCity = `-- name: VenueCountByCity :many
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1
|
||||
`
|
||||
|
||||
type VenueCountByCityRow struct {
|
||||
City string
|
||||
Count int64
|
||||
}
|
||||
|
||||
func (q *Queries) VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error) {
|
||||
rows, err := q.query(ctx, q.venueCountByCityStmt, venueCountByCity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VenueCountByCityRow
|
||||
for rows.Next() {
|
||||
var i VenueCountByCityRow
|
||||
if err := rows.Scan(&i.City, &i.Count); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: city.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createCity = `-- name: CreateCity :one
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
$1,
|
||||
$2
|
||||
) RETURNING slug, name
|
||||
`
|
||||
|
||||
type CreateCityParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
// Create a new city. The slug must be unique.
|
||||
// This is the second line of the comment
|
||||
// This is the third line
|
||||
func (q *Queries) CreateCity(ctx context.Context, arg CreateCityParams) (City, error) {
|
||||
row := q.db.QueryRow(ctx, createCity, arg.Name, arg.Slug)
|
||||
var i City
|
||||
err := row.Scan(&i.Slug, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCity = `-- name: GetCity :one
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
WHERE slug = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCity(ctx context.Context, slug string) (City, error) {
|
||||
row := q.db.QueryRow(ctx, getCity, slug)
|
||||
var i City
|
||||
err := row.Scan(&i.Slug, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCities = `-- name: ListCities :many
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListCities(ctx context.Context) ([]City, error) {
|
||||
rows, err := q.db.Query(ctx, listCities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []City
|
||||
for rows.Next() {
|
||||
var i City
|
||||
if err := rows.Scan(&i.Slug, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateCityName = `-- name: UpdateCityName :exec
|
||||
UPDATE city
|
||||
SET name = $2
|
||||
WHERE slug = $1
|
||||
`
|
||||
|
||||
type UpdateCityNameParams struct {
|
||||
Slug string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error {
|
||||
_, err := q.db.Exec(ctx, updateCityName, arg.Slug, arg.Name)
|
||||
return err
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
// Venues can be either open or closed
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusOpen Status = "op!en"
|
||||
StatusClosed Status = "clo@sed"
|
||||
)
|
||||
|
||||
func (e *Status) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = Status(s)
|
||||
case string:
|
||||
*e = Status(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for Status: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullStatus struct {
|
||||
Status Status
|
||||
Valid bool // Valid is true if Status is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullStatus) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.Status, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.Status.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullStatus) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.Status), nil
|
||||
}
|
||||
|
||||
type City struct {
|
||||
Slug string
|
||||
Name string
|
||||
}
|
||||
|
||||
// Venues are places where muisc happens
|
||||
type Venue struct {
|
||||
ID int32
|
||||
Status Status
|
||||
Statuses pgtype.Array[Status]
|
||||
// This value appears in public URLs
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
SongkickID pgtype.Text
|
||||
Tags pgtype.Array[string]
|
||||
CreatedAt pgtype.Timestamp
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
// Create a new city. The slug must be unique.
|
||||
// This is the second line of the comment
|
||||
// This is the third line
|
||||
CreateCity(ctx context.Context, arg CreateCityParams) (City, error)
|
||||
CreateVenue(ctx context.Context, arg CreateVenueParams) (int32, error)
|
||||
DeleteVenue(ctx context.Context, slug string) error
|
||||
GetCity(ctx context.Context, slug string) (City, error)
|
||||
GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error)
|
||||
ListCities(ctx context.Context) ([]City, error)
|
||||
ListVenues(ctx context.Context, city string) ([]Venue, error)
|
||||
UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error
|
||||
UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) (int32, error)
|
||||
VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
@ -0,0 +1,56 @@
|
||||
-- name: GetAuthor :one
|
||||
SELECT * FROM authors
|
||||
WHERE author_id = $1;
|
||||
|
||||
-- name: DeleteBookExecResult :execresult
|
||||
DELETE FROM books
|
||||
WHERE book_id = $1;
|
||||
|
||||
-- name: DeleteBook :batchexec
|
||||
DELETE FROM books
|
||||
WHERE book_id = $1;
|
||||
|
||||
-- name: DeleteBookNamedFunc :batchexec
|
||||
DELETE FROM books
|
||||
WHERE book_id = sqlc.arg(book_id);
|
||||
|
||||
-- name: DeleteBookNamedSign :batchexec
|
||||
DELETE FROM books
|
||||
WHERE book_id = @book_id;
|
||||
|
||||
-- name: BooksByYear :batchmany
|
||||
SELECT * FROM books
|
||||
WHERE year = $1;
|
||||
|
||||
-- name: CreateAuthor :one
|
||||
INSERT INTO authors (name) VALUES ($1)
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateBook :batchone
|
||||
INSERT INTO books (
|
||||
author_id,
|
||||
isbn,
|
||||
book_type,
|
||||
title,
|
||||
year,
|
||||
available,
|
||||
tags
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateBook :batchexec
|
||||
UPDATE books
|
||||
SET title = $1, tags = $2
|
||||
WHERE book_id = $3;
|
||||
|
||||
-- name: GetBiography :batchone
|
||||
SELECT biography FROM authors
|
||||
WHERE author_id = $1;
|
@ -0,0 +1,26 @@
|
||||
-- name: ListCities :many
|
||||
SELECT *
|
||||
FROM city
|
||||
ORDER BY name;
|
||||
|
||||
-- name: GetCity :one
|
||||
SELECT *
|
||||
FROM city
|
||||
WHERE slug = $1;
|
||||
|
||||
-- name: CreateCity :one
|
||||
-- Create a new city. The slug must be unique.
|
||||
-- This is the second line of the comment
|
||||
-- This is the third line
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
$1,
|
||||
$2
|
||||
) RETURNING *;
|
||||
|
||||
-- name: UpdateCityName :exec
|
||||
UPDATE city
|
||||
SET name = $2
|
||||
WHERE slug = $1;
|
@ -0,0 +1,49 @@
|
||||
-- name: ListVenues :many
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE city = $1
|
||||
ORDER BY name;
|
||||
|
||||
-- name: DeleteVenue :exec
|
||||
DELETE FROM venue
|
||||
WHERE slug = $1 AND slug = $1;
|
||||
|
||||
-- name: GetVenue :one
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE slug = $1 AND city = $2;
|
||||
|
||||
-- name: CreateVenue :one
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
NOW(),
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
) RETURNING id;
|
||||
|
||||
-- name: UpdateVenueName :one
|
||||
UPDATE venue
|
||||
SET name = $2
|
||||
WHERE slug = $1
|
||||
RETURNING id;
|
||||
|
||||
-- name: VenueCountByCity :many
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1;
|
@ -0,0 +1,21 @@
|
||||
CREATE TABLE authors (
|
||||
author_id SERIAL PRIMARY KEY,
|
||||
name text NOT NULL DEFAULT '',
|
||||
biography JSONB
|
||||
);
|
||||
|
||||
CREATE TYPE book_type AS ENUM (
|
||||
'FICTION',
|
||||
'NONFICTION'
|
||||
);
|
||||
|
||||
CREATE TABLE books (
|
||||
book_id SERIAL PRIMARY KEY,
|
||||
author_id integer NOT NULL REFERENCES authors(author_id),
|
||||
isbn text NOT NULL DEFAULT '' UNIQUE,
|
||||
book_type book_type NOT NULL DEFAULT 'FICTION',
|
||||
title text NOT NULL DEFAULT '',
|
||||
year integer NOT NULL DEFAULT 2000,
|
||||
available timestamp with time zone NOT NULL DEFAULT 'NOW()',
|
||||
tags varchar[] NOT NULL DEFAULT '{}'
|
||||
);
|
@ -0,0 +1,4 @@
|
||||
CREATE TABLE city (
|
||||
slug text PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
)
|
@ -0,0 +1,18 @@
|
||||
CREATE TYPE status AS ENUM ('op!en', 'clo@sed');
|
||||
COMMENT ON TYPE status IS 'Venues can be either open or closed';
|
||||
|
||||
CREATE TABLE venues (
|
||||
id SERIAL primary key,
|
||||
dropped text,
|
||||
status status not null,
|
||||
statuses status[],
|
||||
slug text not null,
|
||||
name varchar(255) not null,
|
||||
city text not null references city(slug),
|
||||
spotify_playlist varchar not null,
|
||||
songkick_id text,
|
||||
tags text[]
|
||||
);
|
||||
COMMENT ON TABLE venues IS 'Venues are places where muisc happens';
|
||||
COMMENT ON COLUMN venues.slug IS 'This value appears in public URLs';
|
||||
|
@ -0,0 +1,3 @@
|
||||
ALTER TABLE venues RENAME TO venue;
|
||||
ALTER TABLE venue ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT NOW();
|
||||
ALTER TABLE venue DROP COLUMN dropped;
|
@ -0,0 +1,189 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: venue.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createVenue = `-- name: CreateVenue :one
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
NOW(),
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
) RETURNING id
|
||||
`
|
||||
|
||||
type CreateVenueParams struct {
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
Status Status
|
||||
Statuses pgtype.Array[Status]
|
||||
Tags pgtype.Array[string]
|
||||
}
|
||||
|
||||
func (q *Queries) CreateVenue(ctx context.Context, arg CreateVenueParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, createVenue,
|
||||
arg.Slug,
|
||||
arg.Name,
|
||||
arg.City,
|
||||
arg.SpotifyPlaylist,
|
||||
arg.Status,
|
||||
arg.Statuses,
|
||||
arg.Tags,
|
||||
)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const deleteVenue = `-- name: DeleteVenue :exec
|
||||
DELETE FROM venue
|
||||
WHERE slug = $1 AND slug = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteVenue(ctx context.Context, slug string) error {
|
||||
_, err := q.db.Exec(ctx, deleteVenue, slug)
|
||||
return err
|
||||
}
|
||||
|
||||
const getVenue = `-- name: GetVenue :one
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE slug = $1 AND city = $2
|
||||
`
|
||||
|
||||
type GetVenueParams struct {
|
||||
Slug string
|
||||
City string
|
||||
}
|
||||
|
||||
func (q *Queries) GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error) {
|
||||
row := q.db.QueryRow(ctx, getVenue, arg.Slug, arg.City)
|
||||
var i Venue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listVenues = `-- name: ListVenues :many
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE city = $1
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListVenues(ctx context.Context, city string) ([]Venue, error) {
|
||||
rows, err := q.db.Query(ctx, listVenues, city)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Venue
|
||||
for rows.Next() {
|
||||
var i Venue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateVenueName = `-- name: UpdateVenueName :one
|
||||
UPDATE venue
|
||||
SET name = $2
|
||||
WHERE slug = $1
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type UpdateVenueNameParams struct {
|
||||
Slug string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, updateVenueName, arg.Slug, arg.Name)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const venueCountByCity = `-- name: VenueCountByCity :many
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1
|
||||
`
|
||||
|
||||
type VenueCountByCityRow struct {
|
||||
City string
|
||||
Count int64
|
||||
}
|
||||
|
||||
func (q *Queries) VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error) {
|
||||
rows, err := q.db.Query(ctx, venueCountByCity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VenueCountByCityRow
|
||||
for rows.Next() {
|
||||
var i VenueCountByCityRow
|
||||
if err := rows.Scan(&i.City, &i.Count); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
version: '2'
|
||||
sql:
|
||||
- schema: postgres/schema
|
||||
queries: postgres/query
|
||||
engine: postgresql
|
||||
gen:
|
||||
go:
|
||||
package: dbr
|
||||
out: postgres
|
||||
sql_package: 'pgx/v5'
|
||||
emit_prepared_queries: true
|
||||
emit_interface: true
|
||||
- schema: mysql/schema
|
||||
queries: mysql/query
|
||||
engine: mysql
|
||||
gen:
|
||||
go:
|
||||
package: dbr
|
||||
out: mysql
|
||||
emit_prepared_queries: true
|
||||
emit_interface: true
|
||||
- schema: sqlite/schema
|
||||
queries: sqlite/query
|
||||
engine: sqlite
|
||||
gen:
|
||||
go:
|
||||
package: dbr
|
||||
out: sqlite
|
||||
emit_prepared_queries: true
|
||||
emit_interface: true
|
@ -0,0 +1,88 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: city.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const createCity = `-- name: CreateCity :exec
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
?,
|
||||
?
|
||||
)
|
||||
`
|
||||
|
||||
type CreateCityParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCity(ctx context.Context, arg CreateCityParams) error {
|
||||
_, err := q.exec(ctx, q.createCityStmt, createCity, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCity = `-- name: GetCity :one
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetCity(ctx context.Context, slug string) (City, error) {
|
||||
row := q.queryRow(ctx, q.getCityStmt, getCity, slug)
|
||||
var i City
|
||||
err := row.Scan(&i.Slug, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCities = `-- name: ListCities :many
|
||||
SELECT slug, name
|
||||
FROM city
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListCities(ctx context.Context) ([]City, error) {
|
||||
rows, err := q.query(ctx, q.listCitiesStmt, listCities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []City
|
||||
for rows.Next() {
|
||||
var i City
|
||||
if err := rows.Scan(&i.Slug, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateCityName = `-- name: UpdateCityName :exec
|
||||
UPDATE city
|
||||
SET name = ?
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
type UpdateCityNameParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error {
|
||||
_, err := q.exec(ctx, q.updateCityNameStmt, updateCityName, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
q := Queries{db: db}
|
||||
var err error
|
||||
if q.createCityStmt, err = db.PrepareContext(ctx, createCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query CreateCity: %w", err)
|
||||
}
|
||||
if q.createVenueStmt, err = db.PrepareContext(ctx, createVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query CreateVenue: %w", err)
|
||||
}
|
||||
if q.deleteVenueStmt, err = db.PrepareContext(ctx, deleteVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query DeleteVenue: %w", err)
|
||||
}
|
||||
if q.getCityStmt, err = db.PrepareContext(ctx, getCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query GetCity: %w", err)
|
||||
}
|
||||
if q.getVenueStmt, err = db.PrepareContext(ctx, getVenue); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query GetVenue: %w", err)
|
||||
}
|
||||
if q.listCitiesStmt, err = db.PrepareContext(ctx, listCities); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListCities: %w", err)
|
||||
}
|
||||
if q.listVenuesStmt, err = db.PrepareContext(ctx, listVenues); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListVenues: %w", err)
|
||||
}
|
||||
if q.updateCityNameStmt, err = db.PrepareContext(ctx, updateCityName); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query UpdateCityName: %w", err)
|
||||
}
|
||||
if q.updateVenueNameStmt, err = db.PrepareContext(ctx, updateVenueName); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query UpdateVenueName: %w", err)
|
||||
}
|
||||
if q.venueCountByCityStmt, err = db.PrepareContext(ctx, venueCountByCity); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query VenueCountByCity: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
func (q *Queries) Close() error {
|
||||
var err error
|
||||
if q.createCityStmt != nil {
|
||||
if cerr := q.createCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing createCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.createVenueStmt != nil {
|
||||
if cerr := q.createVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing createVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.deleteVenueStmt != nil {
|
||||
if cerr := q.deleteVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing deleteVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.getCityStmt != nil {
|
||||
if cerr := q.getCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing getCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.getVenueStmt != nil {
|
||||
if cerr := q.getVenueStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing getVenueStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listCitiesStmt != nil {
|
||||
if cerr := q.listCitiesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listCitiesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listVenuesStmt != nil {
|
||||
if cerr := q.listVenuesStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listVenuesStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.updateCityNameStmt != nil {
|
||||
if cerr := q.updateCityNameStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing updateCityNameStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.updateVenueNameStmt != nil {
|
||||
if cerr := q.updateVenueNameStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing updateVenueNameStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.venueCountByCityStmt != nil {
|
||||
if cerr := q.venueCountByCityStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing venueCountByCityStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.ExecContext(ctx, args...)
|
||||
default:
|
||||
return q.db.ExecContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryRowContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryRowContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
tx *sql.Tx
|
||||
createCityStmt *sql.Stmt
|
||||
createVenueStmt *sql.Stmt
|
||||
deleteVenueStmt *sql.Stmt
|
||||
getCityStmt *sql.Stmt
|
||||
getVenueStmt *sql.Stmt
|
||||
listCitiesStmt *sql.Stmt
|
||||
listVenuesStmt *sql.Stmt
|
||||
updateCityNameStmt *sql.Stmt
|
||||
updateVenueNameStmt *sql.Stmt
|
||||
venueCountByCityStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
tx: tx,
|
||||
createCityStmt: q.createCityStmt,
|
||||
createVenueStmt: q.createVenueStmt,
|
||||
deleteVenueStmt: q.deleteVenueStmt,
|
||||
getCityStmt: q.getCityStmt,
|
||||
getVenueStmt: q.getVenueStmt,
|
||||
listCitiesStmt: q.listCitiesStmt,
|
||||
listVenuesStmt: q.listVenuesStmt,
|
||||
updateCityNameStmt: q.updateCityNameStmt,
|
||||
updateVenueNameStmt: q.updateVenueNameStmt,
|
||||
venueCountByCityStmt: q.venueCountByCityStmt,
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type City struct {
|
||||
Slug string
|
||||
Name string
|
||||
}
|
||||
|
||||
type Venue struct {
|
||||
ID int64
|
||||
Status string
|
||||
Statuses sql.NullString
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
SongkickID sql.NullString
|
||||
Tags sql.NullString
|
||||
CreatedAt time.Time
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
CreateCity(ctx context.Context, arg CreateCityParams) error
|
||||
CreateVenue(ctx context.Context, arg CreateVenueParams) (sql.Result, error)
|
||||
DeleteVenue(ctx context.Context, arg DeleteVenueParams) error
|
||||
GetCity(ctx context.Context, slug string) (City, error)
|
||||
GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error)
|
||||
ListCities(ctx context.Context) ([]City, error)
|
||||
ListVenues(ctx context.Context, city string) ([]Venue, error)
|
||||
UpdateCityName(ctx context.Context, arg UpdateCityNameParams) error
|
||||
UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) error
|
||||
VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
@ -0,0 +1,23 @@
|
||||
/* name: ListCities :many */
|
||||
SELECT *
|
||||
FROM city
|
||||
ORDER BY name;
|
||||
|
||||
/* name: GetCity :one */
|
||||
SELECT *
|
||||
FROM city
|
||||
WHERE slug = ?;
|
||||
|
||||
/* name: CreateCity :exec */
|
||||
INSERT INTO city (
|
||||
name,
|
||||
slug
|
||||
) VALUES (
|
||||
?,
|
||||
?
|
||||
);
|
||||
|
||||
/* name: UpdateCityName :exec */
|
||||
UPDATE city
|
||||
SET name = ?
|
||||
WHERE slug = ?;
|
@ -0,0 +1,48 @@
|
||||
/* name: ListVenues :many */
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE city = ?
|
||||
ORDER BY name;
|
||||
|
||||
/* name: DeleteVenue :exec */
|
||||
DELETE FROM venue
|
||||
WHERE slug = ? AND slug = ?;
|
||||
|
||||
/* name: GetVenue :one */
|
||||
SELECT *
|
||||
FROM venue
|
||||
WHERE slug = ? AND city = ?;
|
||||
|
||||
/* name: CreateVenue :execresult */
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
CURRENT_TIMESTAMP,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
);
|
||||
|
||||
/* name: UpdateVenueName :exec */
|
||||
UPDATE venue
|
||||
SET name = ?
|
||||
WHERE slug = ?;
|
||||
|
||||
/* name: VenueCountByCity :many */
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1;
|
@ -0,0 +1,4 @@
|
||||
CREATE TABLE city (
|
||||
slug varchar(255) PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
CREATE TABLE venues (
|
||||
id integer primary key AUTOINCREMENT,
|
||||
dropped text,
|
||||
status text not null,
|
||||
statuses text, -- status[]
|
||||
slug text not null,
|
||||
name varchar(255) not null,
|
||||
city text not null references city(slug),
|
||||
spotify_playlist varchar(255) not null,
|
||||
songkick_id text,
|
||||
tags text, -- tags[]
|
||||
CHECK (status = 'open' OR status = 'closed')
|
||||
);
|
@ -0,0 +1,3 @@
|
||||
ALTER TABLE venues RENAME TO venue;
|
||||
ALTER TABLE venue ADD COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
ALTER TABLE venue DROP COLUMN dropped;
|
@ -0,0 +1,193 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.16.0
|
||||
// source: venue.sql
|
||||
|
||||
package dbr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createVenue = `-- name: CreateVenue :execresult
|
||||
INSERT INTO venue (
|
||||
slug,
|
||||
name,
|
||||
city,
|
||||
created_at,
|
||||
spotify_playlist,
|
||||
status,
|
||||
statuses,
|
||||
tags
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
CURRENT_TIMESTAMP,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?
|
||||
)
|
||||
`
|
||||
|
||||
type CreateVenueParams struct {
|
||||
Slug string
|
||||
Name string
|
||||
City string
|
||||
SpotifyPlaylist string
|
||||
Status string
|
||||
Statuses sql.NullString
|
||||
Tags sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateVenue(ctx context.Context, arg CreateVenueParams) (sql.Result, error) {
|
||||
return q.exec(ctx, q.createVenueStmt, createVenue,
|
||||
arg.Slug,
|
||||
arg.Name,
|
||||
arg.City,
|
||||
arg.SpotifyPlaylist,
|
||||
arg.Status,
|
||||
arg.Statuses,
|
||||
arg.Tags,
|
||||
)
|
||||
}
|
||||
|
||||
const deleteVenue = `-- name: DeleteVenue :exec
|
||||
DELETE FROM venue
|
||||
WHERE slug = ? AND slug = ?
|
||||
`
|
||||
|
||||
type DeleteVenueParams struct {
|
||||
Slug string
|
||||
Slug_2 string
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteVenue(ctx context.Context, arg DeleteVenueParams) error {
|
||||
_, err := q.exec(ctx, q.deleteVenueStmt, deleteVenue, arg.Slug, arg.Slug_2)
|
||||
return err
|
||||
}
|
||||
|
||||
const getVenue = `-- name: GetVenue :one
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE slug = ? AND city = ?
|
||||
`
|
||||
|
||||
type GetVenueParams struct {
|
||||
Slug string
|
||||
City string
|
||||
}
|
||||
|
||||
func (q *Queries) GetVenue(ctx context.Context, arg GetVenueParams) (Venue, error) {
|
||||
row := q.queryRow(ctx, q.getVenueStmt, getVenue, arg.Slug, arg.City)
|
||||
var i Venue
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listVenues = `-- name: ListVenues :many
|
||||
SELECT id, status, statuses, slug, name, city, spotify_playlist, songkick_id, tags, created_at
|
||||
FROM venue
|
||||
WHERE city = ?
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListVenues(ctx context.Context, city string) ([]Venue, error) {
|
||||
rows, err := q.query(ctx, q.listVenuesStmt, listVenues, city)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Venue
|
||||
for rows.Next() {
|
||||
var i Venue
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Status,
|
||||
&i.Statuses,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.City,
|
||||
&i.SpotifyPlaylist,
|
||||
&i.SongkickID,
|
||||
&i.Tags,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateVenueName = `-- name: UpdateVenueName :exec
|
||||
UPDATE venue
|
||||
SET name = ?
|
||||
WHERE slug = ?
|
||||
`
|
||||
|
||||
type UpdateVenueNameParams struct {
|
||||
Name string
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams) error {
|
||||
_, err := q.exec(ctx, q.updateVenueNameStmt, updateVenueName, arg.Name, arg.Slug)
|
||||
return err
|
||||
}
|
||||
|
||||
const venueCountByCity = `-- name: VenueCountByCity :many
|
||||
SELECT
|
||||
city,
|
||||
count(*)
|
||||
FROM venue
|
||||
GROUP BY 1
|
||||
ORDER BY 1
|
||||
`
|
||||
|
||||
type VenueCountByCityRow struct {
|
||||
City string
|
||||
Count int64
|
||||
}
|
||||
|
||||
func (q *Queries) VenueCountByCity(ctx context.Context) ([]VenueCountByCityRow, error) {
|
||||
rows, err := q.query(ctx, q.venueCountByCityStmt, venueCountByCity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []VenueCountByCityRow
|
||||
for rows.Next() {
|
||||
var i VenueCountByCityRow
|
||||
if err := rows.Scan(&i.City, &i.Count); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
Loading…
Reference in new issue