Files
warehouse-management-BE/sqlc_gen/container.sql.go
2026-05-11 09:42:19 +07:00

180 lines
4.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: container.sql
package db
import (
"context"
"time"
"github.com/jackc/pgx/v5/pgtype"
)
const createContainer = `-- name: CreateContainer :one
INSERT INTO containers (shelf_id,name,container_type, description,max_capacity,metadata, created_at)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
RETURNING id, shelf_id, name, container_type, description, max_capacity, metadata, created_at, updated_at
`
type CreateContainerParams struct {
ShelfID int64 `db:"shelf_id" json:"shelfId"`
Name string `db:"name" json:"name"`
ContainerType ContainerTypeEnum `db:"container_type" json:"containerType"`
Description pgtype.Text `db:"description" json:"description"`
MaxCapacity pgtype.Int4 `db:"max_capacity" json:"maxCapacity"`
Metadata []byte `db:"metadata" json:"metadata"`
CreatedAt time.Time `db:"created_at" json:"createdAt"`
}
func (q *Queries) CreateContainer(ctx context.Context, arg CreateContainerParams) (Container, error) {
row := q.db.QueryRow(ctx, createContainer,
arg.ShelfID,
arg.Name,
arg.ContainerType,
arg.Description,
arg.MaxCapacity,
arg.Metadata,
arg.CreatedAt,
)
var i Container
err := row.Scan(
&i.ID,
&i.ShelfID,
&i.Name,
&i.ContainerType,
&i.Description,
&i.MaxCapacity,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteContainer = `-- name: DeleteContainer :execrows
DELETE FROM containers
WHERE id = $1
`
func (q *Queries) DeleteContainer(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, deleteContainer, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getContainerByID = `-- name: GetContainerByID :one
SELECT id, shelf_id, name, container_type, description, max_capacity, metadata, created_at, updated_at FROM containers
WHERE id = $1
`
func (q *Queries) GetContainerByID(ctx context.Context, id int64) (Container, error) {
row := q.db.QueryRow(ctx, getContainerByID, id)
var i Container
err := row.Scan(
&i.ID,
&i.ShelfID,
&i.Name,
&i.ContainerType,
&i.Description,
&i.MaxCapacity,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listContainers = `-- name: ListContainers :many
SELECT id, shelf_id, name, container_type, description, max_capacity, metadata, created_at, updated_at FROM containers
ORDER BY created_at DESC
`
func (q *Queries) ListContainers(ctx context.Context) ([]Container, error) {
rows, err := q.db.Query(ctx, listContainers)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Container
for rows.Next() {
var i Container
if err := rows.Scan(
&i.ID,
&i.ShelfID,
&i.Name,
&i.ContainerType,
&i.Description,
&i.MaxCapacity,
&i.Metadata,
&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 updateContainer = `-- name: UpdateContainer :one
UPDATE containers
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
description = coalesce($2, description),
container_type = coalesce($3, container_type),
max_capacity = coalesce($4, max_capacity),
metadata = coalesce($5, metadata),
updated_at = $6
WHERE id = $7
RETURNING id, shelf_id, name, container_type, description, max_capacity, metadata, created_at, updated_at
`
type UpdateContainerParams struct {
Name interface{} `db:"name" json:"name"`
Description pgtype.Text `db:"description" json:"description"`
ContainerType NullContainerTypeEnum `db:"container_type" json:"containerType"`
MaxCapacity pgtype.Int4 `db:"max_capacity" json:"maxCapacity"`
Metadata []byte `db:"metadata" json:"metadata"`
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
ID int64 `db:"id" json:"id"`
}
func (q *Queries) UpdateContainer(ctx context.Context, arg UpdateContainerParams) (Container, error) {
row := q.db.QueryRow(ctx, updateContainer,
arg.Name,
arg.Description,
arg.ContainerType,
arg.MaxCapacity,
arg.Metadata,
arg.UpdatedAt,
arg.ID,
)
var i Container
err := row.Scan(
&i.ID,
&i.ShelfID,
&i.Name,
&i.ContainerType,
&i.Description,
&i.MaxCapacity,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}