297 lines
7.4 KiB
Go
297 lines
7.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: products.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createProduct = `-- name: CreateProduct :execresult
|
|
INSERT INTO products (
|
|
principle_id, product_category_id, title, description,
|
|
model_number, model_number_format, notes, stock,
|
|
item_code, item_description
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
`
|
|
|
|
type CreateProductParams struct {
|
|
PrincipleID int32 `json:"principle_id"`
|
|
ProductCategoryID int32 `json:"product_category_id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
ModelNumber sql.NullString `json:"model_number"`
|
|
ModelNumberFormat sql.NullString `json:"model_number_format"`
|
|
Notes sql.NullString `json:"notes"`
|
|
Stock bool `json:"stock"`
|
|
ItemCode string `json:"item_code"`
|
|
ItemDescription string `json:"item_description"`
|
|
}
|
|
|
|
func (q *Queries) CreateProduct(ctx context.Context, arg CreateProductParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createProduct,
|
|
arg.PrincipleID,
|
|
arg.ProductCategoryID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.ModelNumber,
|
|
arg.ModelNumberFormat,
|
|
arg.Notes,
|
|
arg.Stock,
|
|
arg.ItemCode,
|
|
arg.ItemDescription,
|
|
)
|
|
}
|
|
|
|
const deleteProduct = `-- name: DeleteProduct :exec
|
|
DELETE FROM products
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteProduct(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteProduct, id)
|
|
return err
|
|
}
|
|
|
|
const getProduct = `-- name: GetProduct :one
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetProduct(ctx context.Context, id int32) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, getProduct, id)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.ProductCategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.ModelNumber,
|
|
&i.ModelNumberFormat,
|
|
&i.Notes,
|
|
&i.Stock,
|
|
&i.ItemCode,
|
|
&i.ItemDescription,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getProductByItemCode = `-- name: GetProductByItemCode :one
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
WHERE item_code = ?
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetProductByItemCode(ctx context.Context, itemCode string) (Product, error) {
|
|
row := q.db.QueryRowContext(ctx, getProductByItemCode, itemCode)
|
|
var i Product
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.ProductCategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.ModelNumber,
|
|
&i.ModelNumberFormat,
|
|
&i.Notes,
|
|
&i.Stock,
|
|
&i.ItemCode,
|
|
&i.ItemDescription,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getProductsByCategory = `-- name: GetProductsByCategory :many
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
WHERE product_category_id = ?
|
|
ORDER BY title
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type GetProductsByCategoryParams struct {
|
|
ProductCategoryID int32 `json:"product_category_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) GetProductsByCategory(ctx context.Context, arg GetProductsByCategoryParams) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, getProductsByCategory, arg.ProductCategoryID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.ProductCategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.ModelNumber,
|
|
&i.ModelNumberFormat,
|
|
&i.Notes,
|
|
&i.Stock,
|
|
&i.ItemCode,
|
|
&i.ItemDescription,
|
|
); 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 listProducts = `-- name: ListProducts :many
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
ORDER BY title
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListProductsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListProducts(ctx context.Context, arg ListProductsParams) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, listProducts, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.ProductCategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.ModelNumber,
|
|
&i.ModelNumberFormat,
|
|
&i.Notes,
|
|
&i.Stock,
|
|
&i.ItemCode,
|
|
&i.ItemDescription,
|
|
); 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 searchProductsByTitle = `-- name: SearchProductsByTitle :many
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
WHERE title LIKE CONCAT('%', ?, '%')
|
|
ORDER BY title
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type SearchProductsByTitleParams struct {
|
|
CONCAT interface{} `json:"CONCAT"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) SearchProductsByTitle(ctx context.Context, arg SearchProductsByTitleParams) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, searchProductsByTitle, arg.CONCAT, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Product{}
|
|
for rows.Next() {
|
|
var i Product
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.ProductCategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.ModelNumber,
|
|
&i.ModelNumberFormat,
|
|
&i.Notes,
|
|
&i.Stock,
|
|
&i.ItemCode,
|
|
&i.ItemDescription,
|
|
); 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 updateProduct = `-- name: UpdateProduct :exec
|
|
UPDATE products
|
|
SET principle_id = ?,
|
|
product_category_id = ?,
|
|
title = ?,
|
|
description = ?,
|
|
model_number = ?,
|
|
model_number_format = ?,
|
|
notes = ?,
|
|
stock = ?,
|
|
item_code = ?,
|
|
item_description = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateProductParams struct {
|
|
PrincipleID int32 `json:"principle_id"`
|
|
ProductCategoryID int32 `json:"product_category_id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
ModelNumber sql.NullString `json:"model_number"`
|
|
ModelNumberFormat sql.NullString `json:"model_number_format"`
|
|
Notes sql.NullString `json:"notes"`
|
|
Stock bool `json:"stock"`
|
|
ItemCode string `json:"item_code"`
|
|
ItemDescription string `json:"item_description"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProduct(ctx context.Context, arg UpdateProductParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateProduct,
|
|
arg.PrincipleID,
|
|
arg.ProductCategoryID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.ModelNumber,
|
|
arg.ModelNumberFormat,
|
|
arg.Notes,
|
|
arg.Stock,
|
|
arg.ItemCode,
|
|
arg.ItemDescription,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|