You've already forked reloading-manager
Reviewed-on: rrise/reloading-manager#26 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
254 lines
6.3 KiB
Go
254 lines
6.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: bullets.sql
|
|
|
|
package bullets
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const addBullet = `-- name: AddBullet :one
|
|
insert into bullets (name, weight, diameter, photo, meta, manufacturer_id)
|
|
values ($1, $2, $3, $4, $5, $6)
|
|
returning id
|
|
`
|
|
|
|
type AddBulletParams struct {
|
|
Name string `json:"name"`
|
|
Weight int32 `json:"weight"`
|
|
Diameter int32 `json:"diameter"`
|
|
Photo []byte `json:"photo"`
|
|
Meta []byte `json:"meta"`
|
|
ManufacturerID pgtype.UUID `json:"manufacturer_id"`
|
|
}
|
|
|
|
func (q *Queries) AddBullet(ctx context.Context, arg AddBulletParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, addBullet,
|
|
arg.Name,
|
|
arg.Weight,
|
|
arg.Diameter,
|
|
arg.Photo,
|
|
arg.Meta,
|
|
arg.ManufacturerID,
|
|
)
|
|
var id pgtype.UUID
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const deleteBullet = `-- name: DeleteBullet :exec
|
|
DELETE
|
|
from bullets
|
|
where id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBullet(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteBullet, id)
|
|
return err
|
|
}
|
|
|
|
const forPage = `-- name: ForPage :many
|
|
select bullets.id as id,
|
|
bullets.name as name,
|
|
weight,
|
|
diameter,
|
|
bullets.created_at,
|
|
meta,
|
|
m.id as manufacturer_id,
|
|
m.name as manufacturer_name,
|
|
m.url as manufacturer_url
|
|
from bullets
|
|
join manufacturers m on m.id = bullets.manufacturer_id
|
|
order by manufacturer_name, bullets.name desc
|
|
limit $1 offset $2
|
|
`
|
|
|
|
type ForPageParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ForPageRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Weight int32 `json:"weight"`
|
|
Diameter int32 `json:"diameter"`
|
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
|
Meta []byte `json:"meta"`
|
|
ManufacturerID pgtype.UUID `json:"manufacturer_id"`
|
|
ManufacturerName string `json:"manufacturer_name"`
|
|
ManufacturerUrl pgtype.Text `json:"manufacturer_url"`
|
|
}
|
|
|
|
func (q *Queries) ForPage(ctx context.Context, arg ForPageParams) ([]ForPageRow, error) {
|
|
rows, err := q.db.Query(ctx, forPage, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ForPageRow
|
|
for rows.Next() {
|
|
var i ForPageRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Weight,
|
|
&i.Diameter,
|
|
&i.CreatedAt,
|
|
&i.Meta,
|
|
&i.ManufacturerID,
|
|
&i.ManufacturerName,
|
|
&i.ManufacturerUrl,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getBulletById = `-- name: GetBulletById :one
|
|
select bullets.id as id,
|
|
bullets.name,
|
|
bullets.diameter,
|
|
bullets.weight,
|
|
bullets.meta,
|
|
bullets.photo,
|
|
bullets.created_at,
|
|
m.id as manufactuerer_id,
|
|
m.name as manufacutuer_name,
|
|
m.url as manufacturer_url
|
|
from bullets
|
|
join manufacturers m on m.id = bullets.manufacturer_id
|
|
where bullets.id = $1
|
|
`
|
|
|
|
type GetBulletByIdRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Diameter int32 `json:"diameter"`
|
|
Weight int32 `json:"weight"`
|
|
Meta []byte `json:"meta"`
|
|
Photo []byte `json:"photo"`
|
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
|
ManufactuererID pgtype.UUID `json:"manufactuerer_id"`
|
|
ManufacutuerName string `json:"manufacutuer_name"`
|
|
ManufacturerUrl pgtype.Text `json:"manufacturer_url"`
|
|
}
|
|
|
|
func (q *Queries) GetBulletById(ctx context.Context, id pgtype.UUID) (GetBulletByIdRow, error) {
|
|
row := q.db.QueryRow(ctx, getBulletById, id)
|
|
var i GetBulletByIdRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Diameter,
|
|
&i.Weight,
|
|
&i.Meta,
|
|
&i.Photo,
|
|
&i.CreatedAt,
|
|
&i.ManufactuererID,
|
|
&i.ManufacutuerName,
|
|
&i.ManufacturerUrl,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getBullets = `-- name: GetBullets :many
|
|
select bullets.id as id,
|
|
bullets.name as name,
|
|
weight,
|
|
diameter,
|
|
bullets.created_at,
|
|
meta,
|
|
m.id as manufacturer_id,
|
|
m.name as manufacturer_name,
|
|
m.url as manufacturer_url
|
|
from bullets
|
|
join manufacturers m on m.id = bullets.manufacturer_id
|
|
order by manufacturer_name, bullets.name desc
|
|
`
|
|
|
|
type GetBulletsRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Weight int32 `json:"weight"`
|
|
Diameter int32 `json:"diameter"`
|
|
CreatedAt pgtype.Timestamp `json:"created_at"`
|
|
Meta []byte `json:"meta"`
|
|
ManufacturerID pgtype.UUID `json:"manufacturer_id"`
|
|
ManufacturerName string `json:"manufacturer_name"`
|
|
ManufacturerUrl pgtype.Text `json:"manufacturer_url"`
|
|
}
|
|
|
|
func (q *Queries) GetBullets(ctx context.Context) ([]GetBulletsRow, error) {
|
|
rows, err := q.db.Query(ctx, getBullets)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetBulletsRow
|
|
for rows.Next() {
|
|
var i GetBulletsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Weight,
|
|
&i.Diameter,
|
|
&i.CreatedAt,
|
|
&i.Meta,
|
|
&i.ManufacturerID,
|
|
&i.ManufacturerName,
|
|
&i.ManufacturerUrl,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBullet = `-- name: UpdateBullet :exec
|
|
UPDATE bullets
|
|
set name=$1,
|
|
weight=$2,
|
|
diameter=$3,
|
|
photo=$4,
|
|
meta=$5,
|
|
manufacturer_id=$6
|
|
where id = $7
|
|
`
|
|
|
|
type UpdateBulletParams struct {
|
|
Name string `json:"name"`
|
|
Weight int32 `json:"weight"`
|
|
Diameter int32 `json:"diameter"`
|
|
Photo []byte `json:"photo"`
|
|
Meta []byte `json:"meta"`
|
|
ManufacturerID pgtype.UUID `json:"manufacturer_id"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBullet(ctx context.Context, arg UpdateBulletParams) error {
|
|
_, err := q.db.Exec(ctx, updateBullet,
|
|
arg.Name,
|
|
arg.Weight,
|
|
arg.Diameter,
|
|
arg.Photo,
|
|
arg.Meta,
|
|
arg.ManufacturerID,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|