251 lines
6.2 KiB
Go
251 lines
6.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: customers.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createCustomer = `-- name: CreateCustomer :execresult
|
|
INSERT INTO customers (
|
|
name, trading_name, abn, created, notes,
|
|
discount_pricing_policies, payment_terms,
|
|
customer_category_id, url, country_id
|
|
) VALUES (
|
|
?, ?, ?, NOW(), ?, ?, ?, ?, ?, ?
|
|
)
|
|
`
|
|
|
|
type CreateCustomerParams struct {
|
|
Name string `json:"name"`
|
|
TradingName string `json:"trading_name"`
|
|
Abn sql.NullString `json:"abn"`
|
|
Notes string `json:"notes"`
|
|
DiscountPricingPolicies string `json:"discount_pricing_policies"`
|
|
PaymentTerms string `json:"payment_terms"`
|
|
CustomerCategoryID int32 `json:"customer_category_id"`
|
|
Url string `json:"url"`
|
|
CountryID int32 `json:"country_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createCustomer,
|
|
arg.Name,
|
|
arg.TradingName,
|
|
arg.Abn,
|
|
arg.Notes,
|
|
arg.DiscountPricingPolicies,
|
|
arg.PaymentTerms,
|
|
arg.CustomerCategoryID,
|
|
arg.Url,
|
|
arg.CountryID,
|
|
)
|
|
}
|
|
|
|
const deleteCustomer = `-- name: DeleteCustomer :exec
|
|
DELETE FROM customers
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteCustomer(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteCustomer, id)
|
|
return err
|
|
}
|
|
|
|
const getCustomer = `-- name: GetCustomer :one
|
|
SELECT id, name, trading_name, abn, created, notes, discount_pricing_policies, payment_terms, customer_category_id, url, country_id FROM customers
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCustomer(ctx context.Context, id int32) (Customer, error) {
|
|
row := q.db.QueryRowContext(ctx, getCustomer, id)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.TradingName,
|
|
&i.Abn,
|
|
&i.Created,
|
|
&i.Notes,
|
|
&i.DiscountPricingPolicies,
|
|
&i.PaymentTerms,
|
|
&i.CustomerCategoryID,
|
|
&i.Url,
|
|
&i.CountryID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCustomerByABN = `-- name: GetCustomerByABN :one
|
|
SELECT id, name, trading_name, abn, created, notes, discount_pricing_policies, payment_terms, customer_category_id, url, country_id FROM customers
|
|
WHERE abn = ?
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCustomerByABN(ctx context.Context, abn sql.NullString) (Customer, error) {
|
|
row := q.db.QueryRowContext(ctx, getCustomerByABN, abn)
|
|
var i Customer
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.TradingName,
|
|
&i.Abn,
|
|
&i.Created,
|
|
&i.Notes,
|
|
&i.DiscountPricingPolicies,
|
|
&i.PaymentTerms,
|
|
&i.CustomerCategoryID,
|
|
&i.Url,
|
|
&i.CountryID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listCustomers = `-- name: ListCustomers :many
|
|
SELECT id, name, trading_name, abn, created, notes, discount_pricing_policies, payment_terms, customer_category_id, url, country_id FROM customers
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
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.QueryContext(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.TradingName,
|
|
&i.Abn,
|
|
&i.Created,
|
|
&i.Notes,
|
|
&i.DiscountPricingPolicies,
|
|
&i.PaymentTerms,
|
|
&i.CustomerCategoryID,
|
|
&i.Url,
|
|
&i.CountryID,
|
|
); 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 searchCustomersByName = `-- name: SearchCustomersByName :many
|
|
SELECT id, name, trading_name, abn, created, notes, discount_pricing_policies, payment_terms, customer_category_id, url, country_id FROM customers
|
|
WHERE name LIKE CONCAT('%', ?, '%')
|
|
OR trading_name LIKE CONCAT('%', ?, '%')
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type SearchCustomersByNameParams struct {
|
|
CONCAT interface{} `json:"CONCAT"`
|
|
CONCAT_2 interface{} `json:"CONCAT_2"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) SearchCustomersByName(ctx context.Context, arg SearchCustomersByNameParams) ([]Customer, error) {
|
|
rows, err := q.db.QueryContext(ctx, searchCustomersByName,
|
|
arg.CONCAT,
|
|
arg.CONCAT_2,
|
|
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.TradingName,
|
|
&i.Abn,
|
|
&i.Created,
|
|
&i.Notes,
|
|
&i.DiscountPricingPolicies,
|
|
&i.PaymentTerms,
|
|
&i.CustomerCategoryID,
|
|
&i.Url,
|
|
&i.CountryID,
|
|
); 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 updateCustomer = `-- name: UpdateCustomer :exec
|
|
UPDATE customers
|
|
SET name = ?,
|
|
trading_name = ?,
|
|
abn = ?,
|
|
notes = ?,
|
|
discount_pricing_policies = ?,
|
|
payment_terms = ?,
|
|
customer_category_id = ?,
|
|
url = ?,
|
|
country_id = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateCustomerParams struct {
|
|
Name string `json:"name"`
|
|
TradingName string `json:"trading_name"`
|
|
Abn sql.NullString `json:"abn"`
|
|
Notes string `json:"notes"`
|
|
DiscountPricingPolicies string `json:"discount_pricing_policies"`
|
|
PaymentTerms string `json:"payment_terms"`
|
|
CustomerCategoryID int32 `json:"customer_category_id"`
|
|
Url string `json:"url"`
|
|
CountryID int32 `json:"country_id"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCustomer(ctx context.Context, arg UpdateCustomerParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateCustomer,
|
|
arg.Name,
|
|
arg.TradingName,
|
|
arg.Abn,
|
|
arg.Notes,
|
|
arg.DiscountPricingPolicies,
|
|
arg.PaymentTerms,
|
|
arg.CustomerCategoryID,
|
|
arg.Url,
|
|
arg.CountryID,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|