138 lines
3.0 KiB
Go
138 lines
3.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.17.2
|
|
// source: purchase_order.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createPurchaseOrder = `-- name: CreatePurchaseOrder :one
|
|
INSERT INTO purchase_order (
|
|
merchant_id,
|
|
supplier_id,
|
|
code,
|
|
is_paid,
|
|
total,
|
|
paid_nominal,
|
|
note,
|
|
created_by
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8
|
|
)
|
|
RETURNING id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
|
`
|
|
|
|
type CreatePurchaseOrderParams struct {
|
|
MerchantID uuid.UUID `json:"merchant_id"`
|
|
SupplierID uuid.UUID `json:"supplier_id"`
|
|
Code sql.NullString `json:"code"`
|
|
IsPaid bool `json:"is_paid"`
|
|
Total float64 `json:"total"`
|
|
PaidNominal float64 `json:"paid_nominal"`
|
|
Note sql.NullString `json:"note"`
|
|
CreatedBy uuid.UUID `json:"created_by"`
|
|
}
|
|
|
|
func (q *Queries) CreatePurchaseOrder(ctx context.Context, arg CreatePurchaseOrderParams) (PurchaseOrder, error) {
|
|
row := q.db.QueryRowContext(ctx, createPurchaseOrder,
|
|
arg.MerchantID,
|
|
arg.SupplierID,
|
|
arg.Code,
|
|
arg.IsPaid,
|
|
arg.Total,
|
|
arg.PaidNominal,
|
|
arg.Note,
|
|
arg.CreatedBy,
|
|
)
|
|
var i PurchaseOrder
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SupplierID,
|
|
&i.MerchantID,
|
|
&i.IndexID,
|
|
&i.CreatedBy,
|
|
&i.Code,
|
|
&i.IsPaid,
|
|
&i.Total,
|
|
&i.PaidNominal,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPurchaseOrderById = `-- name: GetPurchaseOrderById :one
|
|
SELECT id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
|
FROM purchase_order
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPurchaseOrderById(ctx context.Context, id uuid.UUID) (PurchaseOrder, error) {
|
|
row := q.db.QueryRowContext(ctx, getPurchaseOrderById, id)
|
|
var i PurchaseOrder
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SupplierID,
|
|
&i.MerchantID,
|
|
&i.IndexID,
|
|
&i.CreatedBy,
|
|
&i.Code,
|
|
&i.IsPaid,
|
|
&i.Total,
|
|
&i.PaidNominal,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listPurchaseOrderByMerchantId = `-- name: ListPurchaseOrderByMerchantId :many
|
|
SELECT id, supplier_id, merchant_id, index_id, created_by, code, is_paid, total, paid_nominal, note, created_at, updated_at
|
|
FROM purchase_order
|
|
WHERE merchant_id = $1
|
|
`
|
|
|
|
func (q *Queries) ListPurchaseOrderByMerchantId(ctx context.Context, merchantID uuid.UUID) ([]PurchaseOrder, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPurchaseOrderByMerchantId, merchantID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []PurchaseOrder{}
|
|
for rows.Next() {
|
|
var i PurchaseOrder
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SupplierID,
|
|
&i.MerchantID,
|
|
&i.IndexID,
|
|
&i.CreatedBy,
|
|
&i.Code,
|
|
&i.IsPaid,
|
|
&i.Total,
|
|
&i.PaidNominal,
|
|
&i.Note,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); 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
|
|
}
|