330 lines
9.1 KiB
Go
330 lines
9.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: query.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createDelivery = `-- name: CreateDelivery :one
|
|
INSERT INTO deliveries (
|
|
date, pickup_location, pickup_location_2, product_name, product_name_2,
|
|
customer_name, address, street, house, apartment, entrance, floor,
|
|
phone, additional_phone, has_elevator, service_info, comment
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
|
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor
|
|
`
|
|
|
|
type CreateDeliveryParams struct {
|
|
Date pgtype.Date `db:"date" json:"date"`
|
|
PickupLocation string `db:"pickup_location" json:"pickup_location"`
|
|
PickupLocation2 pgtype.Text `db:"pickup_location_2" json:"pickup_location_2"`
|
|
ProductName string `db:"product_name" json:"product_name"`
|
|
ProductName2 pgtype.Text `db:"product_name_2" json:"product_name_2"`
|
|
CustomerName string `db:"customer_name" json:"customer_name"`
|
|
Address string `db:"address" json:"address"`
|
|
Street string `db:"street" json:"street"`
|
|
House string `db:"house" json:"house"`
|
|
Apartment pgtype.Text `db:"apartment" json:"apartment"`
|
|
Entrance pgtype.Text `db:"entrance" json:"entrance"`
|
|
Floor pgtype.Text `db:"floor" json:"floor"`
|
|
Phone string `db:"phone" json:"phone"`
|
|
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
|
|
HasElevator bool `db:"has_elevator" json:"has_elevator"`
|
|
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
|
|
Comment pgtype.Text `db:"comment" json:"comment"`
|
|
}
|
|
|
|
func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams) (Delivery, error) {
|
|
row := q.db.QueryRow(ctx, createDelivery,
|
|
arg.Date,
|
|
arg.PickupLocation,
|
|
arg.PickupLocation2,
|
|
arg.ProductName,
|
|
arg.ProductName2,
|
|
arg.CustomerName,
|
|
arg.Address,
|
|
arg.Street,
|
|
arg.House,
|
|
arg.Apartment,
|
|
arg.Entrance,
|
|
arg.Floor,
|
|
arg.Phone,
|
|
arg.AdditionalPhone,
|
|
arg.HasElevator,
|
|
arg.ServiceInfo,
|
|
arg.Comment,
|
|
)
|
|
var i Delivery
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Date,
|
|
&i.PickupLocation,
|
|
&i.ProductName,
|
|
&i.Address,
|
|
&i.Phone,
|
|
&i.AdditionalPhone,
|
|
&i.HasElevator,
|
|
&i.Comment,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CustomerName,
|
|
&i.ServiceInfo,
|
|
&i.PickupLocation2,
|
|
&i.ProductName2,
|
|
&i.Street,
|
|
&i.House,
|
|
&i.Apartment,
|
|
&i.Entrance,
|
|
&i.Floor,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (username, password_hash)
|
|
VALUES ($1, $2)
|
|
RETURNING id, username, password_hash, created_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `db:"username" json:"username"`
|
|
PasswordHash string `db:"password_hash" json:"password_hash"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRow(ctx, createUser, arg.Username, arg.PasswordHash)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteDelivery = `-- name: DeleteDelivery :exec
|
|
DELETE FROM deliveries WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteDelivery(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteDelivery, id)
|
|
return err
|
|
}
|
|
|
|
const getDeliveriesByDate = `-- name: GetDeliveriesByDate :many
|
|
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor FROM deliveries WHERE date = $1
|
|
`
|
|
|
|
func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]Delivery, error) {
|
|
rows, err := q.db.Query(ctx, getDeliveriesByDate, date)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Delivery{}
|
|
for rows.Next() {
|
|
var i Delivery
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Date,
|
|
&i.PickupLocation,
|
|
&i.ProductName,
|
|
&i.Address,
|
|
&i.Phone,
|
|
&i.AdditionalPhone,
|
|
&i.HasElevator,
|
|
&i.Comment,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CustomerName,
|
|
&i.ServiceInfo,
|
|
&i.PickupLocation2,
|
|
&i.ProductName2,
|
|
&i.Street,
|
|
&i.House,
|
|
&i.Apartment,
|
|
&i.Entrance,
|
|
&i.Floor,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getDeliveryByID = `-- name: GetDeliveryByID :one
|
|
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor FROM deliveries WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error) {
|
|
row := q.db.QueryRow(ctx, getDeliveryByID, id)
|
|
var i Delivery
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Date,
|
|
&i.PickupLocation,
|
|
&i.ProductName,
|
|
&i.Address,
|
|
&i.Phone,
|
|
&i.AdditionalPhone,
|
|
&i.HasElevator,
|
|
&i.Comment,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CustomerName,
|
|
&i.ServiceInfo,
|
|
&i.PickupLocation2,
|
|
&i.ProductName2,
|
|
&i.Street,
|
|
&i.House,
|
|
&i.Apartment,
|
|
&i.Entrance,
|
|
&i.Floor,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getDeliveryCount = `-- name: GetDeliveryCount :many
|
|
SELECT COUNT(*) as count, date FROM deliveries
|
|
WHERE date >= CURRENT_DATE AND date < CURRENT_DATE + INTERVAL '7 days'
|
|
GROUP BY date
|
|
`
|
|
|
|
type GetDeliveryCountRow struct {
|
|
Count int64 `db:"count" json:"count"`
|
|
Date pgtype.Date `db:"date" json:"date"`
|
|
}
|
|
|
|
func (q *Queries) GetDeliveryCount(ctx context.Context) ([]GetDeliveryCountRow, error) {
|
|
rows, err := q.db.Query(ctx, getDeliveryCount)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetDeliveryCountRow{}
|
|
for rows.Next() {
|
|
var i GetDeliveryCountRow
|
|
if err := rows.Scan(&i.Count, &i.Date); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
SELECT id, username, password_hash, created_at FROM users WHERE username = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByUsername, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateDelivery = `-- name: UpdateDelivery :exec
|
|
UPDATE deliveries SET
|
|
date = $1,
|
|
pickup_location = $2,
|
|
pickup_location_2 = $3,
|
|
product_name = $4,
|
|
product_name_2 = $5,
|
|
customer_name = $6,
|
|
address = $7,
|
|
street = $8,
|
|
house = $9,
|
|
apartment = $10,
|
|
entrance = $11,
|
|
floor = $12,
|
|
phone = $13,
|
|
additional_phone = $14,
|
|
has_elevator = $15,
|
|
service_info = $16,
|
|
comment = $17,
|
|
updated_at = NOW()
|
|
WHERE id = $18
|
|
`
|
|
|
|
type UpdateDeliveryParams struct {
|
|
Date pgtype.Date `db:"date" json:"date"`
|
|
PickupLocation string `db:"pickup_location" json:"pickup_location"`
|
|
PickupLocation2 pgtype.Text `db:"pickup_location_2" json:"pickup_location_2"`
|
|
ProductName string `db:"product_name" json:"product_name"`
|
|
ProductName2 pgtype.Text `db:"product_name_2" json:"product_name_2"`
|
|
CustomerName string `db:"customer_name" json:"customer_name"`
|
|
Address string `db:"address" json:"address"`
|
|
Street string `db:"street" json:"street"`
|
|
House string `db:"house" json:"house"`
|
|
Apartment pgtype.Text `db:"apartment" json:"apartment"`
|
|
Entrance pgtype.Text `db:"entrance" json:"entrance"`
|
|
Floor pgtype.Text `db:"floor" json:"floor"`
|
|
Phone string `db:"phone" json:"phone"`
|
|
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
|
|
HasElevator bool `db:"has_elevator" json:"has_elevator"`
|
|
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
|
|
Comment pgtype.Text `db:"comment" json:"comment"`
|
|
ID pgtype.UUID `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateDelivery(ctx context.Context, arg UpdateDeliveryParams) error {
|
|
_, err := q.db.Exec(ctx, updateDelivery,
|
|
arg.Date,
|
|
arg.PickupLocation,
|
|
arg.PickupLocation2,
|
|
arg.ProductName,
|
|
arg.ProductName2,
|
|
arg.CustomerName,
|
|
arg.Address,
|
|
arg.Street,
|
|
arg.House,
|
|
arg.Apartment,
|
|
arg.Entrance,
|
|
arg.Floor,
|
|
arg.Phone,
|
|
arg.AdditionalPhone,
|
|
arg.HasElevator,
|
|
arg.ServiceInfo,
|
|
arg.Comment,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateDeliveryStatus = `-- name: UpdateDeliveryStatus :exec
|
|
UPDATE deliveries SET status = $1, updated_at = NOW() WHERE id = $2
|
|
`
|
|
|
|
type UpdateDeliveryStatusParams struct {
|
|
Status string `db:"status" json:"status"`
|
|
ID pgtype.UUID `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateDeliveryStatus(ctx context.Context, arg UpdateDeliveryStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateDeliveryStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|