260 lines
5.9 KiB
Go
260 lines
5.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: addresses.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createAddress = `-- name: CreateAddress :execresult
|
|
INSERT INTO addresses (
|
|
name, address, city, state_id, country_id,
|
|
customer_id, type, postcode
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?, ?
|
|
)
|
|
`
|
|
|
|
type CreateAddressParams struct {
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
City string `json:"city"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
Type string `json:"type"`
|
|
Postcode string `json:"postcode"`
|
|
}
|
|
|
|
func (q *Queries) CreateAddress(ctx context.Context, arg CreateAddressParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createAddress,
|
|
arg.Name,
|
|
arg.Address,
|
|
arg.City,
|
|
arg.StateID,
|
|
arg.CountryID,
|
|
arg.CustomerID,
|
|
arg.Type,
|
|
arg.Postcode,
|
|
)
|
|
}
|
|
|
|
const deleteAddress = `-- name: DeleteAddress :exec
|
|
DELETE FROM addresses
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteAddress(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteAddress, id)
|
|
return err
|
|
}
|
|
|
|
const getAddress = `-- name: GetAddress :one
|
|
SELECT id, name, address, city, state_id, country_id, customer_id, type, postcode FROM addresses
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetAddress(ctx context.Context, id int32) (Address, error) {
|
|
row := q.db.QueryRowContext(ctx, getAddress, id)
|
|
var i Address
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Address,
|
|
&i.City,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.CustomerID,
|
|
&i.Type,
|
|
&i.Postcode,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getCustomerAddresses = `-- name: GetCustomerAddresses :many
|
|
SELECT a.id, a.name, a.address, a.city, a.state_id, a.country_id, a.customer_id, a.type, a.postcode, s.name as state_name, s.shortform as state_shortform, c.name as country_name
|
|
FROM addresses a
|
|
LEFT JOIN states s ON a.state_id = s.id
|
|
LEFT JOIN countries c ON a.country_id = c.id
|
|
WHERE a.customer_id = ?
|
|
ORDER BY a.name
|
|
`
|
|
|
|
type GetCustomerAddressesRow struct {
|
|
ID int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
City string `json:"city"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
Type string `json:"type"`
|
|
Postcode string `json:"postcode"`
|
|
StateName sql.NullString `json:"state_name"`
|
|
StateShortform sql.NullString `json:"state_shortform"`
|
|
CountryName sql.NullString `json:"country_name"`
|
|
}
|
|
|
|
func (q *Queries) GetCustomerAddresses(ctx context.Context, customerID int32) ([]GetCustomerAddressesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getCustomerAddresses, customerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetCustomerAddressesRow{}
|
|
for rows.Next() {
|
|
var i GetCustomerAddressesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Address,
|
|
&i.City,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.CustomerID,
|
|
&i.Type,
|
|
&i.Postcode,
|
|
&i.StateName,
|
|
&i.StateShortform,
|
|
&i.CountryName,
|
|
); 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 listAddresses = `-- name: ListAddresses :many
|
|
SELECT id, name, address, city, state_id, country_id, customer_id, type, postcode FROM addresses
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListAddressesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListAddresses(ctx context.Context, arg ListAddressesParams) ([]Address, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAddresses, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Address{}
|
|
for rows.Next() {
|
|
var i Address
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Address,
|
|
&i.City,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.CustomerID,
|
|
&i.Type,
|
|
&i.Postcode,
|
|
); 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 listAddressesByCustomer = `-- name: ListAddressesByCustomer :many
|
|
SELECT id, name, address, city, state_id, country_id, customer_id, type, postcode FROM addresses
|
|
WHERE customer_id = ?
|
|
ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListAddressesByCustomer(ctx context.Context, customerID int32) ([]Address, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAddressesByCustomer, customerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Address{}
|
|
for rows.Next() {
|
|
var i Address
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Address,
|
|
&i.City,
|
|
&i.StateID,
|
|
&i.CountryID,
|
|
&i.CustomerID,
|
|
&i.Type,
|
|
&i.Postcode,
|
|
); 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 updateAddress = `-- name: UpdateAddress :exec
|
|
UPDATE addresses
|
|
SET name = ?,
|
|
address = ?,
|
|
city = ?,
|
|
state_id = ?,
|
|
country_id = ?,
|
|
customer_id = ?,
|
|
type = ?,
|
|
postcode = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateAddressParams struct {
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
City string `json:"city"`
|
|
StateID int32 `json:"state_id"`
|
|
CountryID int32 `json:"country_id"`
|
|
CustomerID int32 `json:"customer_id"`
|
|
Type string `json:"type"`
|
|
Postcode string `json:"postcode"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateAddress(ctx context.Context, arg UpdateAddressParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateAddress,
|
|
arg.Name,
|
|
arg.Address,
|
|
arg.City,
|
|
arg.StateID,
|
|
arg.CountryID,
|
|
arg.CustomerID,
|
|
arg.Type,
|
|
arg.Postcode,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|