the rest
This commit is contained in:
212
internal/db/bookings.sql.go
Normal file
212
internal/db/bookings.sql.go
Normal file
@@ -0,0 +1,212 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: bookings.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
const createBooking = `-- name: CreateBooking :one
|
||||
INSERT INTO bookings (user_id, service_id, event_date, address, notes, status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
`
|
||||
|
||||
type CreateBookingParams struct {
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
type CreateBookingRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBooking(ctx context.Context, arg CreateBookingParams) (CreateBookingRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, createBooking,
|
||||
arg.UserID,
|
||||
arg.ServiceID,
|
||||
arg.EventDate,
|
||||
arg.Address,
|
||||
arg.Notes,
|
||||
arg.Status,
|
||||
)
|
||||
var i CreateBookingRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBooking = `-- name: GetBooking :one
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type GetBookingRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetBooking(ctx context.Context, id int64) (GetBookingRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getBooking, id)
|
||||
var i GetBookingRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBookingsByUser = `-- name: ListBookingsByUser :many
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE user_id = $1
|
||||
ORDER BY event_date DESC
|
||||
`
|
||||
|
||||
type ListBookingsByUserRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBookingsByUser(ctx context.Context, userID sql.NullInt64) ([]ListBookingsByUserRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listBookingsByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListBookingsByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListBookingsByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
); 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 listBookingsWithServiceByUser = `-- name: ListBookingsWithServiceByUser :many
|
||||
SELECT
|
||||
b.id,
|
||||
b.user_id,
|
||||
b.service_id,
|
||||
b.event_date,
|
||||
b.address,
|
||||
b.notes,
|
||||
b.created_at,
|
||||
b.status,
|
||||
s.name as service_name,
|
||||
s.description as service_description,
|
||||
s.price_cents as service_price_cents
|
||||
FROM bookings b
|
||||
JOIN services s ON b.service_id = s.id
|
||||
WHERE b.user_id = $1
|
||||
ORDER BY b.event_date DESC
|
||||
`
|
||||
|
||||
type ListBookingsWithServiceByUserRow struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Status sql.NullString `json:"status"`
|
||||
ServiceName string `json:"service_name"`
|
||||
ServiceDescription sql.NullString `json:"service_description"`
|
||||
ServicePriceCents int32 `json:"service_price_cents"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListBookingsWithServiceByUser(ctx context.Context, userID sql.NullInt64) ([]ListBookingsWithServiceByUserRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listBookingsWithServiceByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListBookingsWithServiceByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListBookingsWithServiceByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.ServiceID,
|
||||
&i.EventDate,
|
||||
&i.Address,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.Status,
|
||||
&i.ServiceName,
|
||||
&i.ServiceDescription,
|
||||
&i.ServicePriceCents,
|
||||
); 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
|
||||
}
|
||||
68
internal/db/data.go
Normal file
68
internal/db/data.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
)
|
||||
|
||||
func OpenDB(ctx context.Context) (*sql.DB, error) {
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
if dsn == "" {
|
||||
host := getenv("DB_HOST", "localhost")
|
||||
port := getenv("DB_PORT", "5432")
|
||||
user := getenv("DB_USER", "party")
|
||||
pass := getenv("DB_PASS", "secret")
|
||||
name := getenv("DB_NAME", "partydb")
|
||||
ssl := getenv("DB_SSLMODE", "disable")
|
||||
dsn = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", user, pass, host, port, name, ssl)
|
||||
}
|
||||
|
||||
db, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Connection pool tuning
|
||||
if v := os.Getenv("DB_MAX_OPEN_CONNS"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
db.SetMaxOpenConns(n)
|
||||
}
|
||||
} else {
|
||||
db.SetMaxOpenConns(25)
|
||||
}
|
||||
if v := os.Getenv("DB_MAX_IDLE_CONNS"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
db.SetMaxIdleConns(n)
|
||||
}
|
||||
} else {
|
||||
db.SetMaxIdleConns(25)
|
||||
}
|
||||
if v := os.Getenv("DB_CONN_MAX_LIFETIME"); v != "" {
|
||||
if d, err := time.ParseDuration(v); err == nil {
|
||||
db.SetConnMaxLifetime(d)
|
||||
}
|
||||
} else {
|
||||
db.SetConnMaxLifetime(30 * time.Minute)
|
||||
}
|
||||
|
||||
ctxPing, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
if err := db.PingContext(ctxPing); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func getenv(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
31
internal/db/db.go
Normal file
31
internal/db/db.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
123
internal/db/gallery_photos.sql.go
Normal file
123
internal/db/gallery_photos.sql.go
Normal file
@@ -0,0 +1,123 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: gallery_photos.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createGalleryPhoto = `-- name: CreateGalleryPhoto :one
|
||||
INSERT INTO gallery_photos (image_url, caption, created_at, show_on_home)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, image_url, caption, created_at, show_on_home
|
||||
`
|
||||
|
||||
type CreateGalleryPhotoParams struct {
|
||||
ImageUrl string `json:"image_url"`
|
||||
Caption sql.NullString `json:"caption"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
ShowOnHome sql.NullBool `json:"show_on_home"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateGalleryPhoto(ctx context.Context, arg CreateGalleryPhotoParams) (GalleryPhoto, error) {
|
||||
row := q.db.QueryRowContext(ctx, createGalleryPhoto,
|
||||
arg.ImageUrl,
|
||||
arg.Caption,
|
||||
arg.CreatedAt,
|
||||
arg.ShowOnHome,
|
||||
)
|
||||
var i GalleryPhoto
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ImageUrl,
|
||||
&i.Caption,
|
||||
&i.CreatedAt,
|
||||
&i.ShowOnHome,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteGalleryPhoto = `-- name: DeleteGalleryPhoto :exec
|
||||
DELETE FROM gallery_photos
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteGalleryPhoto(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteGalleryPhoto, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const listGalleryPhotos = `-- name: ListGalleryPhotos :many
|
||||
SELECT id, image_url, caption, created_at, show_on_home
|
||||
FROM gallery_photos
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListGalleryPhotos(ctx context.Context) ([]GalleryPhoto, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listGalleryPhotos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GalleryPhoto{}
|
||||
for rows.Next() {
|
||||
var i GalleryPhoto
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ImageUrl,
|
||||
&i.Caption,
|
||||
&i.CreatedAt,
|
||||
&i.ShowOnHome,
|
||||
); 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 listHomeCarouselPhotos = `-- name: ListHomeCarouselPhotos :many
|
||||
SELECT id, image_url, caption, created_at, show_on_home
|
||||
FROM gallery_photos
|
||||
WHERE show_on_home = true
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListHomeCarouselPhotos(ctx context.Context) ([]GalleryPhoto, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listHomeCarouselPhotos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []GalleryPhoto{}
|
||||
for rows.Next() {
|
||||
var i GalleryPhoto
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ImageUrl,
|
||||
&i.Caption,
|
||||
&i.CreatedAt,
|
||||
&i.ShowOnHome,
|
||||
); 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
|
||||
}
|
||||
44
internal/db/models.go
Normal file
44
internal/db/models.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Booking struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID sql.NullInt64 `json:"user_id"`
|
||||
ServiceID sql.NullInt64 `json:"service_id"`
|
||||
EventDate time.Time `json:"event_date"`
|
||||
Notes sql.NullString `json:"notes"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
Address sql.NullString `json:"address"`
|
||||
Status sql.NullString `json:"status"`
|
||||
}
|
||||
|
||||
type GalleryPhoto struct {
|
||||
ID int64 `json:"id"`
|
||||
ImageUrl string `json:"image_url"`
|
||||
Caption sql.NullString `json:"caption"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
ShowOnHome sql.NullBool `json:"show_on_home"`
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description sql.NullString `json:"description"`
|
||||
PriceCents int32 `json:"price_cents"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
OryIdentityID sql.NullString `json:"ory_identity_id"`
|
||||
}
|
||||
33
internal/db/queries/bookings.sql
Normal file
33
internal/db/queries/bookings.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
-- name: CreateBooking :one
|
||||
INSERT INTO bookings (user_id, service_id, event_date, address, notes, status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, user_id, service_id, event_date, address, notes, created_at, status;
|
||||
|
||||
-- name: ListBookingsByUser :many
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE user_id = $1
|
||||
ORDER BY event_date DESC;
|
||||
|
||||
-- name: ListBookingsWithServiceByUser :many
|
||||
SELECT
|
||||
b.id,
|
||||
b.user_id,
|
||||
b.service_id,
|
||||
b.event_date,
|
||||
b.address,
|
||||
b.notes,
|
||||
b.created_at,
|
||||
b.status,
|
||||
s.name as service_name,
|
||||
s.description as service_description,
|
||||
s.price_cents as service_price_cents
|
||||
FROM bookings b
|
||||
JOIN services s ON b.service_id = s.id
|
||||
WHERE b.user_id = $1
|
||||
ORDER BY b.event_date DESC;
|
||||
|
||||
-- name: GetBooking :one
|
||||
SELECT id, user_id, service_id, event_date, address, notes, created_at, status
|
||||
FROM bookings
|
||||
WHERE id = $1;
|
||||
19
internal/db/queries/gallery_photos.sql
Normal file
19
internal/db/queries/gallery_photos.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- name: ListGalleryPhotos :many
|
||||
SELECT id, image_url, caption, created_at, show_on_home
|
||||
FROM gallery_photos
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: ListHomeCarouselPhotos :many
|
||||
SELECT id, image_url, caption, created_at, show_on_home
|
||||
FROM gallery_photos
|
||||
WHERE show_on_home = true
|
||||
ORDER BY created_at DESC;
|
||||
|
||||
-- name: CreateGalleryPhoto :one
|
||||
INSERT INTO gallery_photos (image_url, caption, created_at, show_on_home)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, image_url, caption, created_at, show_on_home;
|
||||
|
||||
-- name: DeleteGalleryPhoto :exec
|
||||
DELETE FROM gallery_photos
|
||||
WHERE id = $1;
|
||||
14
internal/db/queries/services.sql
Normal file
14
internal/db/queries/services.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- name: ListServices :many
|
||||
SELECT id, name, description, price_cents, created_at
|
||||
FROM services
|
||||
ORDER BY id DESC;
|
||||
|
||||
-- name: GetService :one
|
||||
SELECT id, name, description, price_cents, created_at
|
||||
FROM services
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: CreateService :one
|
||||
INSERT INTO services (name, description, price_cents, created_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, description, price_cents, created_at;
|
||||
16
internal/db/queries/users.sql
Normal file
16
internal/db/queries/users.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- name: GetUserByEmail :one
|
||||
SELECT * FROM users WHERE email = $1 LIMIT 1;
|
||||
|
||||
-- name: GetUserByOryID :one
|
||||
SELECT * FROM users WHERE ory_identity_id = $1 LIMIT 1;
|
||||
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (email, ory_identity_id)
|
||||
VALUES ($1, $2)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateUserOryID :one
|
||||
UPDATE users
|
||||
SET ory_identity_id = $1
|
||||
WHERE email = $2
|
||||
RETURNING *;
|
||||
96
internal/db/services.sql.go
Normal file
96
internal/db/services.sql.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: services.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createService = `-- name: CreateService :one
|
||||
INSERT INTO services (name, description, price_cents, created_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, description, price_cents, created_at
|
||||
`
|
||||
|
||||
type CreateServiceParams struct {
|
||||
Name string `json:"name"`
|
||||
Description sql.NullString `json:"description"`
|
||||
PriceCents int32 `json:"price_cents"`
|
||||
CreatedAt sql.NullTime `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateService(ctx context.Context, arg CreateServiceParams) (Service, error) {
|
||||
row := q.db.QueryRowContext(ctx, createService,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.PriceCents,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i Service
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.PriceCents,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getService = `-- name: GetService :one
|
||||
SELECT id, name, description, price_cents, created_at
|
||||
FROM services
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetService(ctx context.Context, id int64) (Service, error) {
|
||||
row := q.db.QueryRowContext(ctx, getService, id)
|
||||
var i Service
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.PriceCents,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listServices = `-- name: ListServices :many
|
||||
SELECT id, name, description, price_cents, created_at
|
||||
FROM services
|
||||
ORDER BY id DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListServices(ctx context.Context) ([]Service, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listServices)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Service{}
|
||||
for rows.Next() {
|
||||
var i Service
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.PriceCents,
|
||||
&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
|
||||
}
|
||||
90
internal/db/users.sql.go
Normal file
90
internal/db/users.sql.go
Normal file
@@ -0,0 +1,90 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: users.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (email, ory_identity_id)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, email, created_at, ory_identity_id
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
Email string `json:"email"`
|
||||
OryIdentityID sql.NullString `json:"ory_identity_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, createUser, arg.Email, arg.OryIdentityID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.OryIdentityID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, created_at, ory_identity_id FROM users WHERE email = $1 LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserByEmail, email)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.OryIdentityID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByOryID = `-- name: GetUserByOryID :one
|
||||
SELECT id, email, created_at, ory_identity_id FROM users WHERE ory_identity_id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByOryID(ctx context.Context, oryIdentityID sql.NullString) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserByOryID, oryIdentityID)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.OryIdentityID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateUserOryID = `-- name: UpdateUserOryID :one
|
||||
UPDATE users
|
||||
SET ory_identity_id = $1
|
||||
WHERE email = $2
|
||||
RETURNING id, email, created_at, ory_identity_id
|
||||
`
|
||||
|
||||
type UpdateUserOryIDParams struct {
|
||||
OryIdentityID sql.NullString `json:"ory_identity_id"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUserOryID(ctx context.Context, arg UpdateUserOryIDParams) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, updateUserOryID, arg.OryIdentityID, arg.Email)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.CreatedAt,
|
||||
&i.OryIdentityID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user