147 lines
3.0 KiB
Go
147 lines
3.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: room.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createRoom = `-- name: CreateRoom :one
|
|
INSERT INTO rooms (warehouse_id,name, description, created_at)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4
|
|
)
|
|
RETURNING id, warehouse_id, name, description, created_at, updated_at
|
|
`
|
|
|
|
type CreateRoomParams struct {
|
|
WarehouseID int64 `db:"warehouse_id" json:"warehouseId"`
|
|
Name string `db:"name" json:"name"`
|
|
Description pgtype.Text `db:"description" json:"description"`
|
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
|
}
|
|
|
|
func (q *Queries) CreateRoom(ctx context.Context, arg CreateRoomParams) (Room, error) {
|
|
row := q.db.QueryRow(ctx, createRoom,
|
|
arg.WarehouseID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.CreatedAt,
|
|
)
|
|
var i Room
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WarehouseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteRoom = `-- name: DeleteRoom :exec
|
|
DELETE FROM rooms
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteRoom(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, deleteRoom, id)
|
|
return err
|
|
}
|
|
|
|
const getRoomByID = `-- name: GetRoomByID :one
|
|
SELECT id, warehouse_id, name, description, created_at, updated_at FROM rooms
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetRoomByID(ctx context.Context, id int64) (Room, error) {
|
|
row := q.db.QueryRow(ctx, getRoomByID, id)
|
|
var i Room
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WarehouseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listRooms = `-- name: ListRooms :many
|
|
SELECT id, warehouse_id, name, description, created_at, updated_at FROM rooms
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListRooms(ctx context.Context) ([]Room, error) {
|
|
rows, err := q.db.Query(ctx, listRooms)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Room
|
|
for rows.Next() {
|
|
var i Room
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.WarehouseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&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 updateRoom = `-- name: UpdateRoom :one
|
|
UPDATE rooms
|
|
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
|
|
description = coalesce($2, description),
|
|
updated_at = $3
|
|
WHERE id = $4
|
|
RETURNING id, warehouse_id, name, description, created_at, updated_at
|
|
`
|
|
|
|
type UpdateRoomParams struct {
|
|
Name interface{} `db:"name" json:"name"`
|
|
Description pgtype.Text `db:"description" json:"description"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
|
ID int64 `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateRoom(ctx context.Context, arg UpdateRoomParams) (Room, error) {
|
|
row := q.db.QueryRow(ctx, updateRoom,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
)
|
|
var i Room
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.WarehouseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|