205 lines
5.0 KiB
Go
205 lines
5.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: invoice.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createInvoice = `-- name: CreateInvoice :one
|
|
INSERT INTO invoices (type, status, invoice_config_id, total_items, note, created_by, approved_by, created_at, metadata)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9
|
|
)
|
|
RETURNING id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata
|
|
`
|
|
|
|
type CreateInvoiceParams struct {
|
|
Type InvoiceTypeEnum `db:"type" json:"type"`
|
|
Status InvoiceStatusEnum `db:"status" json:"status"`
|
|
InvoiceConfigID pgtype.Int8 `db:"invoice_config_id" json:"invoiceConfigId"`
|
|
TotalItems int32 `db:"total_items" json:"totalItems"`
|
|
Note pgtype.Text `db:"note" json:"note"`
|
|
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
|
ApprovedBy pgtype.Text `db:"approved_by" json:"approvedBy"`
|
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) CreateInvoice(ctx context.Context, arg CreateInvoiceParams) (Invoice, error) {
|
|
row := q.db.QueryRow(ctx, createInvoice,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.InvoiceConfigID,
|
|
arg.TotalItems,
|
|
arg.Note,
|
|
arg.CreatedBy,
|
|
arg.ApprovedBy,
|
|
arg.CreatedAt,
|
|
arg.Metadata,
|
|
)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceCode,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.InvoiceConfigID,
|
|
&i.TotalItems,
|
|
&i.Note,
|
|
&i.CreatedBy,
|
|
&i.ApprovedBy,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteInvoice = `-- name: DeleteInvoice :execrows
|
|
DELETE FROM invoices
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteInvoice(ctx context.Context, id int64) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteInvoice, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getInvoiceByID = `-- name: GetInvoiceByID :one
|
|
SELECT id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata FROM invoices
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetInvoiceByID(ctx context.Context, id int64) (Invoice, error) {
|
|
row := q.db.QueryRow(ctx, getInvoiceByID, id)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceCode,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.InvoiceConfigID,
|
|
&i.TotalItems,
|
|
&i.Note,
|
|
&i.CreatedBy,
|
|
&i.ApprovedBy,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listInvoices = `-- name: ListInvoices :many
|
|
SELECT id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata FROM invoices
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListInvoices(ctx context.Context) ([]Invoice, error) {
|
|
rows, err := q.db.Query(ctx, listInvoices)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Invoice
|
|
for rows.Next() {
|
|
var i Invoice
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.InvoiceCode,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.InvoiceConfigID,
|
|
&i.TotalItems,
|
|
&i.Note,
|
|
&i.CreatedBy,
|
|
&i.ApprovedBy,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Metadata,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateInvoice = `-- name: UpdateInvoice :one
|
|
UPDATE invoices
|
|
SET type = coalesce($1, type),
|
|
status = coalesce($2, status),
|
|
invoice_config_id = coalesce($3, invoice_config_id),
|
|
total_items = coalesce($4, total_items),
|
|
note = coalesce($5, note),
|
|
metadata = coalesce($6, metadata),
|
|
updated_at = $7
|
|
WHERE id = $8
|
|
RETURNING id, invoice_code, type, status, invoice_config_id, total_items, note, created_by, approved_by, completed_at, created_at, updated_at, metadata
|
|
`
|
|
|
|
type UpdateInvoiceParams struct {
|
|
Type InvoiceTypeEnum `db:"type" json:"type"`
|
|
Status InvoiceStatusEnum `db:"status" json:"status"`
|
|
InvoiceConfigID pgtype.Int8 `db:"invoice_config_id" json:"invoiceConfigId"`
|
|
TotalItems int32 `db:"total_items" json:"totalItems"`
|
|
Note pgtype.Text `db:"note" json:"note"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
|
ID int64 `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateInvoice(ctx context.Context, arg UpdateInvoiceParams) (Invoice, error) {
|
|
row := q.db.QueryRow(ctx, updateInvoice,
|
|
arg.Type,
|
|
arg.Status,
|
|
arg.InvoiceConfigID,
|
|
arg.TotalItems,
|
|
arg.Note,
|
|
arg.Metadata,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
)
|
|
var i Invoice
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.InvoiceCode,
|
|
&i.Type,
|
|
&i.Status,
|
|
&i.InvoiceConfigID,
|
|
&i.TotalItems,
|
|
&i.Note,
|
|
&i.CreatedBy,
|
|
&i.ApprovedBy,
|
|
&i.CompletedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|