Files
delivery-tracker/backend/internal/db/sqlc/query.sql.go
Egor Pozharov be0b13acbf add auth module
2026-04-15 19:17:10 +06:00

242 lines
6.5 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, product_name, address, phone, additional_phone, has_elevator, comment)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at
`
type CreateDeliveryParams struct {
Date pgtype.Date `db:"date" json:"date"`
PickupLocation string `db:"pickup_location" json:"pickup_location"`
ProductName string `db:"product_name" json:"product_name"`
Address string `db:"address" json:"address"`
Phone string `db:"phone" json:"phone"`
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
HasElevator bool `db:"has_elevator" json:"has_elevator"`
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.ProductName,
arg.Address,
arg.Phone,
arg.AdditionalPhone,
arg.HasElevator,
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,
)
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 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,
); 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 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,
)
return i, err
}
const getDeliveryCount = `-- name: GetDeliveryCount :many
SELECT COUNT(*) as count, date FROM deliveries WHERE date >= DATE_TRUNC('month', CURRENT_DATE) 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, product_name = $3, address = $4, phone = $5, additional_phone = $6, has_elevator = $7, comment = $8, updated_at = NOW() WHERE id = $9
`
type UpdateDeliveryParams struct {
Date pgtype.Date `db:"date" json:"date"`
PickupLocation string `db:"pickup_location" json:"pickup_location"`
ProductName string `db:"product_name" json:"product_name"`
Address string `db:"address" json:"address"`
Phone string `db:"phone" json:"phone"`
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
HasElevator bool `db:"has_elevator" json:"has_elevator"`
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.ProductName,
arg.Address,
arg.Phone,
arg.AdditionalPhone,
arg.HasElevator,
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
}