247 lines
5.5 KiB
Go
247 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: customer.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const allCustomers = `-- name: AllCustomers :many
|
|
SELECT id, name, category, source, address, contact_name, contact_phone, status, sort, created_at, created_by, updated_at, updated_by FROM customers
|
|
WHERE status = 0
|
|
ORDER BY id DESC
|
|
`
|
|
|
|
func (q *Queries) AllCustomers(ctx context.Context) ([]*Customer, error) {
|
|
rows, err := q.db.Query(ctx, allCustomers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Customer{}
|
|
for rows.Next() {
|
|
var i Customer
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.Address,
|
|
&i.ContactName,
|
|
&i.ContactPhone,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedBy,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const countCustomers = `-- name: CountCustomers :one
|
|
SELECT COUNT(1)
|
|
FROM customers
|
|
WHERE status = 0
|
|
`
|
|
|
|
func (q *Queries) CountCustomers(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countCustomers)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createCustomer = `-- name: CreateCustomer :one
|
|
INSERT INTO customers (id, name, category, source, address, contact_name, contact_phone, created_by)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING id, name, category, source, address, contact_name, contact_phone, status, sort, created_at, created_by, updated_at, updated_by
|
|
`
|
|
|
|
type CreateCustomerParams struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Category int32 `json:"category"`
|
|
Source int32 `json:"source"`
|
|
Address string `json:"address"`
|
|
ContactName string `json:"contact_name"`
|
|
ContactPhone string `json:"contact_phone"`
|
|
CreatedBy int32 `json:"created_by"`
|
|
}
|
|
|
|
func (q *Queries) CreateCustomer(ctx context.Context, arg *CreateCustomerParams) (*Customer, error) {
|
|
row := q.db.QueryRow(ctx, createCustomer,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.Category,
|
|
arg.Source,
|
|
arg.Address,
|
|
arg.ContactName,
|
|
arg.ContactPhone,
|
|
arg.CreatedBy,
|
|
)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.Address,
|
|
&i.ContactName,
|
|
&i.ContactPhone,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedBy,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getCustomer = `-- name: GetCustomer :one
|
|
SELECT id, name, category, source, address, contact_name, contact_phone, status, sort, created_at, created_by, updated_at, updated_by
|
|
FROM customers
|
|
WHERE id = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCustomer(ctx context.Context, id int64) (*Customer, error) {
|
|
row := q.db.QueryRow(ctx, getCustomer, id)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.Address,
|
|
&i.ContactName,
|
|
&i.ContactPhone,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedBy,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listCustomers = `-- name: ListCustomers :many
|
|
SELECT id, name, category, source, address, contact_name, contact_phone, status, sort, created_at, created_by, updated_at, updated_by
|
|
FROM customers
|
|
WHERE status = 0
|
|
ORDER BY id DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListCustomersParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListCustomers(ctx context.Context, arg *ListCustomersParams) ([]*Customer, error) {
|
|
rows, err := q.db.Query(ctx, listCustomers, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Customer{}
|
|
for rows.Next() {
|
|
var i Customer
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.Address,
|
|
&i.ContactName,
|
|
&i.ContactPhone,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedBy,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateCustomer = `-- name: UpdateCustomer :one
|
|
UPDATE customers
|
|
SET
|
|
name = COALESCE($2, name),
|
|
category = COALESCE($3, category),
|
|
source = COALESCE($4, source),
|
|
address = COALESCE($5, address),
|
|
contact_name = COALESCE($6, contact_name),
|
|
contact_phone = COALESCE($7, contact_phone),
|
|
status = COALESCE($8, status),
|
|
updated_by = COALESCE($9, updated_by),
|
|
updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING id, name, category, source, address, contact_name, contact_phone, status, sort, created_at, created_by, updated_at, updated_by
|
|
`
|
|
|
|
type UpdateCustomerParams struct {
|
|
ID int64 `json:"id"`
|
|
Name pgtype.Text `json:"name"`
|
|
Category pgtype.Int4 `json:"category"`
|
|
Source pgtype.Int4 `json:"source"`
|
|
Address pgtype.Text `json:"address"`
|
|
ContactName pgtype.Text `json:"contact_name"`
|
|
ContactPhone pgtype.Text `json:"contact_phone"`
|
|
Status pgtype.Int2 `json:"status"`
|
|
UpdatedBy pgtype.Int4 `json:"updated_by"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCustomer(ctx context.Context, arg *UpdateCustomerParams) (*Customer, error) {
|
|
row := q.db.QueryRow(ctx, updateCustomer,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.Category,
|
|
arg.Source,
|
|
arg.Address,
|
|
arg.ContactName,
|
|
arg.ContactPhone,
|
|
arg.Status,
|
|
arg.UpdatedBy,
|
|
)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.Source,
|
|
&i.Address,
|
|
&i.ContactName,
|
|
&i.ContactPhone,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedBy,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedBy,
|
|
)
|
|
return &i, err
|
|
}
|