144 lines
3.3 KiB
Go
144 lines
3.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: principles.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createPrinciple = `-- name: CreatePrinciple :execresult
|
|
INSERT INTO principles (name, short_name, code) VALUES (?, ?, ?)
|
|
`
|
|
|
|
type CreatePrincipleParams struct {
|
|
Name string `json:"name"`
|
|
ShortName sql.NullString `json:"short_name"`
|
|
Code int32 `json:"code"`
|
|
}
|
|
|
|
func (q *Queries) CreatePrinciple(ctx context.Context, arg CreatePrincipleParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createPrinciple, arg.Name, arg.ShortName, arg.Code)
|
|
}
|
|
|
|
const getPrinciple = `-- name: GetPrinciple :one
|
|
SELECT id, name, short_name, code FROM principles
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetPrinciple(ctx context.Context, id int32) (Principle, error) {
|
|
row := q.db.QueryRowContext(ctx, getPrinciple, id)
|
|
var i Principle
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ShortName,
|
|
&i.Code,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPrincipleProducts = `-- name: GetPrincipleProducts :many
|
|
SELECT id, principle_id, product_category_id, title, description, model_number, model_number_format, notes, stock, item_code, item_description FROM products
|
|
WHERE principle_id = ?
|
|
ORDER BY title
|
|
`
|
|
|
|
func (q *Queries) GetPrincipleProducts(ctx context.Context, principleID int32) ([]Product, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPrincipleProducts, principleID)
|
|
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 listPrinciples = `-- name: ListPrinciples :many
|
|
SELECT id, name, short_name, code FROM principles
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListPrinciplesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListPrinciples(ctx context.Context, arg ListPrinciplesParams) ([]Principle, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPrinciples, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Principle{}
|
|
for rows.Next() {
|
|
var i Principle
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ShortName,
|
|
&i.Code,
|
|
); 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 updatePrinciple = `-- name: UpdatePrinciple :exec
|
|
UPDATE principles SET name = ?, short_name = ?, code = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdatePrincipleParams struct {
|
|
Name string `json:"name"`
|
|
ShortName sql.NullString `json:"short_name"`
|
|
Code int32 `json:"code"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePrinciple(ctx context.Context, arg UpdatePrincipleParams) error {
|
|
_, err := q.db.ExecContext(ctx, updatePrinciple,
|
|
arg.Name,
|
|
arg.ShortName,
|
|
arg.Code,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|