251 lines
4.0 KiB
Go
251 lines
4.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: item.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const deleteItem = `-- name: DeleteItem :exec
|
|
DELETE FROM item
|
|
WHERE
|
|
id = ?1
|
|
AND
|
|
user_id = ?2
|
|
`
|
|
|
|
type DeleteItemParams struct {
|
|
ID int64
|
|
UserID int64
|
|
}
|
|
|
|
func (q *Queries) DeleteItem(ctx context.Context, arg DeleteItemParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteItem, arg.ID, arg.UserID)
|
|
return err
|
|
}
|
|
|
|
const getItem = `-- name: GetItem :one
|
|
SELECT
|
|
id,
|
|
name,
|
|
added,
|
|
description,
|
|
price,
|
|
quantity,
|
|
user_id
|
|
FROM item
|
|
WHERE
|
|
id = ?1
|
|
AND
|
|
user_id = ?2
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetItemParams struct {
|
|
ID int64
|
|
UserID int64
|
|
}
|
|
|
|
func (q *Queries) GetItem(ctx context.Context, arg GetItemParams) (Item, error) {
|
|
row := q.db.QueryRowContext(ctx, getItem, arg.ID, arg.UserID)
|
|
var i Item
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Added,
|
|
&i.Description,
|
|
&i.Price,
|
|
&i.Quantity,
|
|
&i.UserID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getItems = `-- name: GetItems :many
|
|
SELECT
|
|
id,
|
|
name,
|
|
added,
|
|
description,
|
|
price,
|
|
quantity,
|
|
user_id
|
|
FROM item
|
|
WHERE
|
|
user_id = ?1
|
|
AND
|
|
(
|
|
(name LIKE ?2 OR ?2 IS NULL)
|
|
AND
|
|
(added >= ?3 OR ?3 IS NULL)
|
|
AND
|
|
(added <= ?4 OR ?4 IS NULL)
|
|
)
|
|
LIMIT
|
|
?6
|
|
OFFSET
|
|
?5
|
|
`
|
|
|
|
type GetItemsParams struct {
|
|
UserID int64
|
|
Name *string
|
|
Start *time.Time
|
|
End *time.Time
|
|
Offset int64
|
|
Limit int64
|
|
}
|
|
|
|
func (q *Queries) GetItems(ctx context.Context, arg GetItemsParams) ([]Item, error) {
|
|
rows, err := q.db.QueryContext(ctx, getItems,
|
|
arg.UserID,
|
|
arg.Name,
|
|
arg.Start,
|
|
arg.End,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Item
|
|
for rows.Next() {
|
|
var i Item
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Added,
|
|
&i.Description,
|
|
&i.Price,
|
|
&i.Quantity,
|
|
&i.UserID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getItemsCount = `-- name: GetItemsCount :one
|
|
SELECT COUNT(id)
|
|
FROM item
|
|
WHERE
|
|
user_id = ?1
|
|
AND
|
|
(
|
|
(name LIKE ?2 OR ?2 IS NULL)
|
|
AND
|
|
(added >= ?3 OR ?3 IS NULL)
|
|
AND
|
|
(added <= ?4 OR ?4 IS NULL)
|
|
)
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetItemsCountParams struct {
|
|
UserID int64
|
|
Name *string
|
|
Start *time.Time
|
|
End *time.Time
|
|
}
|
|
|
|
func (q *Queries) GetItemsCount(ctx context.Context, arg GetItemsCountParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, getItemsCount,
|
|
arg.UserID,
|
|
arg.Name,
|
|
arg.Start,
|
|
arg.End,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const insertItem = `-- name: InsertItem :one
|
|
INSERT INTO item (
|
|
name,
|
|
added,
|
|
description,
|
|
price,
|
|
quantity,
|
|
user_id
|
|
) VALUES (
|
|
?1,
|
|
?2,
|
|
?3,
|
|
?4,
|
|
?5,
|
|
?6
|
|
)
|
|
RETURNING id
|
|
`
|
|
|
|
type InsertItemParams struct {
|
|
Name string
|
|
Added time.Time
|
|
Description string
|
|
Price float64
|
|
Quantity int64
|
|
UserID int64
|
|
}
|
|
|
|
func (q *Queries) InsertItem(ctx context.Context, arg InsertItemParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, insertItem,
|
|
arg.Name,
|
|
arg.Added,
|
|
arg.Description,
|
|
arg.Price,
|
|
arg.Quantity,
|
|
arg.UserID,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const updateItem = `-- name: UpdateItem :exec
|
|
UPDATE item
|
|
SET
|
|
name = COALESCE(?1, name),
|
|
description = COALESCE(?2, description),
|
|
price = COALESCE(?3, price),
|
|
quantity = COALESCE(?4, quantity)
|
|
WHERE
|
|
id = ?5
|
|
AND
|
|
user_id = ?6
|
|
`
|
|
|
|
type UpdateItemParams struct {
|
|
Name *string
|
|
Description *string
|
|
Price *float64
|
|
Quantity *int64
|
|
ID int64
|
|
UserID int64
|
|
}
|
|
|
|
func (q *Queries) UpdateItem(ctx context.Context, arg UpdateItemParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateItem,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Price,
|
|
arg.Quantity,
|
|
arg.ID,
|
|
arg.UserID,
|
|
)
|
|
return err
|
|
}
|