121 lines
2.6 KiB
Go
121 lines
2.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.17.2
|
|
// source: customers.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const createCustomers = `-- name: CreateCustomers :one
|
|
INSERT INTO customers (
|
|
merchant_id,
|
|
name,
|
|
detail
|
|
) VALUES (
|
|
$1, $2, $3
|
|
)
|
|
RETURNING id, index_id, merchant_id, name, detail, created_at, updated_at
|
|
`
|
|
|
|
type CreateCustomersParams struct {
|
|
MerchantID uuid.UUID `json:"merchant_id"`
|
|
Name string `json:"name"`
|
|
Detail []json.RawMessage `json:"detail"`
|
|
}
|
|
|
|
func (q *Queries) CreateCustomers(ctx context.Context, arg CreateCustomersParams) (Customer, error) {
|
|
row := q.db.QueryRowContext(ctx, createCustomers, arg.MerchantID, arg.Name, pq.Array(arg.Detail))
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.IndexID,
|
|
&i.MerchantID,
|
|
&i.Name,
|
|
pq.Array(&i.Detail),
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const customersList = `-- name: CustomersList :many
|
|
SELECT id, index_id, merchant_id, name, detail, created_at, updated_at FROM customers
|
|
WHERE merchant_id = $1
|
|
ORDER BY index_id
|
|
LIMIT $2
|
|
OFFSET $3
|
|
`
|
|
|
|
type CustomersListParams struct {
|
|
MerchantID uuid.UUID `json:"merchant_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) CustomersList(ctx context.Context, arg CustomersListParams) ([]Customer, error) {
|
|
rows, err := q.db.QueryContext(ctx, customersList, arg.MerchantID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Customer
|
|
for rows.Next() {
|
|
var i Customer
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.IndexID,
|
|
&i.MerchantID,
|
|
&i.Name,
|
|
pq.Array(&i.Detail),
|
|
&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
|
|
}
|
|
|
|
const deleteCustomer = `-- name: DeleteCustomer :exec
|
|
DELETE FROM customers where id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCustomer(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, deleteCustomer, id)
|
|
return err
|
|
}
|
|
|
|
const updateCustomer = `-- name: UpdateCustomer :one
|
|
SELECT id, index_id, merchant_id, name, detail, created_at, updated_at FROM customers
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) UpdateCustomer(ctx context.Context, id uuid.UUID) (Customer, error) {
|
|
row := q.db.QueryRowContext(ctx, updateCustomer, id)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.IndexID,
|
|
&i.MerchantID,
|
|
&i.Name,
|
|
pq.Array(&i.Detail),
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|