167 lines
4.9 KiB
Go
167 lines
4.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: alternative_component.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createAlternativeComponent = `-- name: CreateAlternativeComponent :one
|
|
INSERT INTO alternative_components (invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6
|
|
)
|
|
RETURNING id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata
|
|
`
|
|
|
|
type CreateAlternativeComponentParams struct {
|
|
InvoiceConfigItemID int64 `db:"invoice_config_item_id" json:"invoiceConfigItemId"`
|
|
AlternativeComponentID int64 `db:"alternative_component_id" json:"alternativeComponentId"`
|
|
ConversionRatio pgtype.Numeric `db:"conversion_ratio" json:"conversionRatio"`
|
|
Priority int32 `db:"priority" json:"priority"`
|
|
Note pgtype.Text `db:"note" json:"note"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) CreateAlternativeComponent(ctx context.Context, arg CreateAlternativeComponentParams) (AlternativeComponent, error) {
|
|
row := q.db.QueryRow(ctx, createAlternativeComponent,
|
|
arg.InvoiceConfigItemID,
|
|
arg.AlternativeComponentID,
|
|
arg.ConversionRatio,
|
|
arg.Priority,
|
|
arg.Note,
|
|
arg.Metadata,
|
|
)
|
|
var i AlternativeComponent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceConfigItemID,
|
|
&i.AlternativeComponentID,
|
|
&i.ConversionRatio,
|
|
&i.Priority,
|
|
&i.Note,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteAlternativeComponent = `-- name: DeleteAlternativeComponent :execrows
|
|
DELETE FROM alternative_components
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteAlternativeComponent(ctx context.Context, id int64) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteAlternativeComponent, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getAlternativeComponentByID = `-- name: GetAlternativeComponentByID :one
|
|
SELECT id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata FROM alternative_components
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetAlternativeComponentByID(ctx context.Context, id int64) (AlternativeComponent, error) {
|
|
row := q.db.QueryRow(ctx, getAlternativeComponentByID, id)
|
|
var i AlternativeComponent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceConfigItemID,
|
|
&i.AlternativeComponentID,
|
|
&i.ConversionRatio,
|
|
&i.Priority,
|
|
&i.Note,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listAlternativeComponents = `-- name: ListAlternativeComponents :many
|
|
SELECT id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata FROM alternative_components
|
|
`
|
|
|
|
func (q *Queries) ListAlternativeComponents(ctx context.Context) ([]AlternativeComponent, error) {
|
|
rows, err := q.db.Query(ctx, listAlternativeComponents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AlternativeComponent
|
|
for rows.Next() {
|
|
var i AlternativeComponent
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.InvoiceConfigItemID,
|
|
&i.AlternativeComponentID,
|
|
&i.ConversionRatio,
|
|
&i.Priority,
|
|
&i.Note,
|
|
&i.Metadata,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateAlternativeComponent = `-- name: UpdateAlternativeComponent :one
|
|
UPDATE alternative_components
|
|
SET invoice_config_item_id = coalesce($1, invoice_config_item_id),
|
|
alternative_component_id = coalesce($2, alternative_component_id),
|
|
conversion_ratio = coalesce($3, conversion_ratio),
|
|
priority = coalesce($4, priority),
|
|
note = coalesce($5, note),
|
|
metadata = coalesce($6, metadata)
|
|
WHERE id = $7
|
|
RETURNING id, invoice_config_item_id, alternative_component_id, conversion_ratio, priority, note, metadata
|
|
`
|
|
|
|
type UpdateAlternativeComponentParams struct {
|
|
InvoiceConfigItemID int64 `db:"invoice_config_item_id" json:"invoiceConfigItemId"`
|
|
AlternativeComponentID int64 `db:"alternative_component_id" json:"alternativeComponentId"`
|
|
ConversionRatio pgtype.Numeric `db:"conversion_ratio" json:"conversionRatio"`
|
|
Priority int32 `db:"priority" json:"priority"`
|
|
Note pgtype.Text `db:"note" json:"note"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
ID int64 `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateAlternativeComponent(ctx context.Context, arg UpdateAlternativeComponentParams) (AlternativeComponent, error) {
|
|
row := q.db.QueryRow(ctx, updateAlternativeComponent,
|
|
arg.InvoiceConfigItemID,
|
|
arg.AlternativeComponentID,
|
|
arg.ConversionRatio,
|
|
arg.Priority,
|
|
arg.Note,
|
|
arg.Metadata,
|
|
arg.ID,
|
|
)
|
|
var i AlternativeComponent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceConfigItemID,
|
|
&i.AlternativeComponentID,
|
|
&i.ConversionRatio,
|
|
&i.Priority,
|
|
&i.Note,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|