173 lines
4.1 KiB
Go
173 lines
4.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: invoice_config.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createInvoiceConfig = `-- name: CreateInvoiceConfig :one
|
|
INSERT INTO invoice_configs (name, type, description, is_active, metadata, created_at)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6
|
|
)
|
|
RETURNING id, name, type, description, is_active, metadata, created_at, updated_at
|
|
`
|
|
|
|
type CreateInvoiceConfigParams struct {
|
|
Name string `db:"name" json:"name"`
|
|
Type InvoiceTypeEnum `db:"type" json:"type"`
|
|
Description pgtype.Text `db:"description" json:"description"`
|
|
IsActive bool `db:"is_active" json:"isActive"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
|
}
|
|
|
|
func (q *Queries) CreateInvoiceConfig(ctx context.Context, arg CreateInvoiceConfigParams) (InvoiceConfig, error) {
|
|
row := q.db.QueryRow(ctx, createInvoiceConfig,
|
|
arg.Name,
|
|
arg.Type,
|
|
arg.Description,
|
|
arg.IsActive,
|
|
arg.Metadata,
|
|
arg.CreatedAt,
|
|
)
|
|
var i InvoiceConfig
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteInvoiceConfig = `-- name: DeleteInvoiceConfig :execrows
|
|
DELETE FROM invoice_configs
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteInvoiceConfig(ctx context.Context, id int64) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteInvoiceConfig, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getInvoiceConfigByID = `-- name: GetInvoiceConfigByID :one
|
|
SELECT id, name, type, description, is_active, metadata, created_at, updated_at FROM invoice_configs
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetInvoiceConfigByID(ctx context.Context, id int64) (InvoiceConfig, error) {
|
|
row := q.db.QueryRow(ctx, getInvoiceConfigByID, id)
|
|
var i InvoiceConfig
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listInvoiceConfigs = `-- name: ListInvoiceConfigs :many
|
|
SELECT id, name, type, description, is_active, metadata, created_at, updated_at FROM invoice_configs
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListInvoiceConfigs(ctx context.Context) ([]InvoiceConfig, error) {
|
|
rows, err := q.db.Query(ctx, listInvoiceConfigs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []InvoiceConfig
|
|
for rows.Next() {
|
|
var i InvoiceConfig
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateInvoiceConfig = `-- name: UpdateInvoiceConfig :one
|
|
UPDATE invoice_configs
|
|
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
|
|
type = coalesce($2, type),
|
|
description = coalesce($3, description),
|
|
is_active = coalesce($4, is_active),
|
|
metadata = coalesce($5, metadata),
|
|
updated_at = $6
|
|
WHERE id = $7
|
|
RETURNING id, name, type, description, is_active, metadata, created_at, updated_at
|
|
`
|
|
|
|
type UpdateInvoiceConfigParams struct {
|
|
Name interface{} `db:"name" json:"name"`
|
|
Type InvoiceTypeEnum `db:"type" json:"type"`
|
|
Description pgtype.Text `db:"description" json:"description"`
|
|
IsActive bool `db:"is_active" json:"isActive"`
|
|
Metadata []byte `db:"metadata" json:"metadata"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
|
ID int64 `db:"id" json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateInvoiceConfig(ctx context.Context, arg UpdateInvoiceConfigParams) (InvoiceConfig, error) {
|
|
row := q.db.QueryRow(ctx, updateInvoiceConfig,
|
|
arg.Name,
|
|
arg.Type,
|
|
arg.Description,
|
|
arg.IsActive,
|
|
arg.Metadata,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
)
|
|
var i InvoiceConfig
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Type,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|