150 lines
3.1 KiB
Go
150 lines
3.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: cabinet.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createCabinet = `-- name: CreateCabinet :one
|
|
INSERT INTO cabinets (room_id,name, description, created_at)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4
|
|
)
|
|
RETURNING id, room_id, name, description, created_at, updated_at
|
|
`
|
|
|
|
type CreateCabinetParams struct {
|
|
RoomID int64 `db:"room_id" json:"roomId"`
|
|
Name string `db:"name" json:"name"`
|
|
Description pgtype.Text `db:"description" json:"description"`
|
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
|
}
|
|
|
|
func (q *Queries) CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, error) {
|
|
row := q.db.QueryRow(ctx, createCabinet,
|
|
arg.RoomID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.CreatedAt,
|
|
)
|
|
var i Cabinet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RoomID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteCabinet = `-- name: DeleteCabinet :execrows
|
|
DELETE FROM cabinets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCabinet(ctx context.Context, id int64) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteCabinet, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getCabinetByID = `-- name: GetCabinetByID :one
|
|
SELECT id, room_id, name, description, created_at, updated_at FROM cabinets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCabinetByID(ctx context.Context, id int64) (Cabinet, error) {
|
|
row := q.db.QueryRow(ctx, getCabinetByID, id)
|
|
var i Cabinet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RoomID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listCabinets = `-- name: ListCabinets :many
|
|
SELECT id, room_id, name, description, created_at, updated_at FROM cabinets
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListCabinets(ctx context.Context) ([]Cabinet, error) {
|
|
rows, err := q.db.Query(ctx, listCabinets)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Cabinet
|
|
for rows.Next() {
|
|
var i Cabinet
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.RoomID,
|
|
&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 updateCabinet = `-- name: UpdateCabinet :one
|
|
UPDATE cabinets
|
|
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
|
|
description = coalesce($2, description),
|
|
updated_at = $3
|
|
WHERE id = $4
|
|
RETURNING id, room_id, name, description, created_at, updated_at
|
|
`
|
|
|
|
type UpdateCabinetParams 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) UpdateCabinet(ctx context.Context, arg UpdateCabinetParams) (Cabinet, error) {
|
|
row := q.db.QueryRow(ctx, updateCabinet,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
)
|
|
var i Cabinet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RoomID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|