naise_pos/db/sqlc/customers.sql.go

121 lines
2.6 KiB
Go
Raw Permalink Normal View History

2023-03-05 23:35:41 +07:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
// source: customers.sql
package db
import (
"context"
2023-03-07 18:52:37 +07:00
"encoding/json"
2023-03-05 23:35:41 +07:00
"github.com/google/uuid"
2023-03-07 18:52:37 +07:00
"github.com/lib/pq"
2023-03-05 23:35:41 +07:00
)
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 {
2023-03-07 18:52:37 +07:00
MerchantID uuid.UUID `json:"merchant_id"`
Name string `json:"name"`
Detail []json.RawMessage `json:"detail"`
2023-03-05 23:35:41 +07:00
}
func (q *Queries) CreateCustomers(ctx context.Context, arg CreateCustomersParams) (Customer, error) {
2023-03-07 18:52:37 +07:00
row := q.db.QueryRowContext(ctx, createCustomers, arg.MerchantID, arg.Name, pq.Array(arg.Detail))
2023-03-05 23:35:41 +07:00
var i Customer
err := row.Scan(
&i.ID,
&i.IndexID,
&i.MerchantID,
&i.Name,
2023-03-07 18:52:37 +07:00
pq.Array(&i.Detail),
2023-03-05 23:35:41 +07:00
&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()
2023-03-12 11:01:43 +07:00
items := []Customer{}
2023-03-05 23:35:41 +07:00
for rows.Next() {
var i Customer
if err := rows.Scan(
&i.ID,
&i.IndexID,
&i.MerchantID,
&i.Name,
2023-03-07 18:52:37 +07:00
pq.Array(&i.Detail),
2023-03-05 23:35:41 +07:00
&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,
2023-03-07 18:52:37 +07:00
pq.Array(&i.Detail),
2023-03-05 23:35:41 +07:00
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}