func (q *DBQuerier) InsertCustomer(ctx context.Context, params InsertCustomerParams) (InsertCustomerRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "InsertCustomer")
	row := q.conn.QueryRow(ctx, insertCustomerSQL, params.FirstName, params.LastName, params.Email)
	var item InsertCustomerRow
	if err := row.Scan(&item.CustomerID, &item.FirstName, &item.LastName, &item.Email); err != nil {
		return item, fmt.Errorf("query InsertCustomer: %w", err)
	}
	return item, nil
}
InsertCustomer implements Querier.InsertCustomer.
package order
import (
	"context"
	"fmt"
	"github.com/jackc/pgconn"
	"github.com/jackc/pgtype"
	"github.com/jackc/pgx/v4"
)
type Querier interface {
	CreateTenant(ctx context.Context, key string, name string) (CreateTenantRow, error)
	CreateTenantBatch(batch genericBatch, key string, name string)
	CreateTenantScan(results pgx.BatchResults) (CreateTenantRow, error)
	FindOrdersByCustomer(ctx context.Context, customerID int32) ([]FindOrdersByCustomerRow, error)
	FindOrdersByCustomerBatch(batch genericBatch, customerID int32)
	FindOrdersByCustomerScan(results pgx.BatchResults) ([]FindOrdersByCustomerRow, error)
	FindProductsInOrder(ctx context.Context, orderID int32) ([]FindProductsInOrderRow, error)
	FindProductsInOrderBatch(batch genericBatch, orderID int32)
	FindProductsInOrderScan(results pgx.BatchResults) ([]FindProductsInOrderRow, error)
	InsertCustomer(ctx context.Context, params InsertCustomerParams) (InsertCustomerRow, error)
	InsertCustomerBatch(batch genericBatch, params InsertCustomerParams)
	InsertCustomerScan(results pgx.BatchResults) (InsertCustomerRow, error)
	InsertOrder(ctx context.Context, params InsertOrderParams) (InsertOrderRow, error)
	InsertOrderBatch(batch genericBatch, params InsertOrderParams)
	InsertOrderScan(results pgx.BatchResults) (InsertOrderRow, error)
	FindOrdersByPrice(ctx context.Context, minTotal pgtype.Numeric) ([]FindOrdersByPriceRow, error)
	FindOrdersByPriceBatch(batch genericBatch, minTotal pgtype.Numeric)
	FindOrdersByPriceScan(results pgx.BatchResults) ([]FindOrdersByPriceRow, error)
	FindOrdersMRR(ctx context.Context) ([]FindOrdersMRRRow, error)
	FindOrdersMRRBatch(batch genericBatch)
	FindOrdersMRRScan(results pgx.BatchResults) ([]FindOrdersMRRRow, error)
}
type DBQuerier struct {
	conn  genericConn    
	types *typeResolver  
}
var _ Querier = &DBQuerier{}
type genericConn interface {
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
}
type genericBatch interface {
	Queue(query string, arguments ...interface{})
}
func NewQuerier(conn genericConn) *DBQuerier {
	return NewQuerierConfig(conn, QuerierConfig{})
}
type QuerierConfig struct {
	DataTypes []pgtype.DataType
}
func NewQuerierConfig(conn genericConn, cfg QuerierConfig) *DBQuerier {
	return &DBQuerier{conn: conn, types: newTypeResolver(cfg.DataTypes)}
}
func (q *DBQuerier) WithTx(tx pgx.Tx) (*DBQuerier, error) {
	return &DBQuerier{conn: tx}, nil
}
type preparer interface {
	Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error)
}
func PrepareAllQueries(ctx context.Context, p preparer) error {
	if _, err := p.Prepare(ctx, createTenantSQL, createTenantSQL); err != nil {
		return fmt.Errorf("prepare query 'CreateTenant': %w", err)
	}
	if _, err := p.Prepare(ctx, findOrdersByCustomerSQL, findOrdersByCustomerSQL); err != nil {
		return fmt.Errorf("prepare query 'FindOrdersByCustomer': %w", err)
	}
	if _, err := p.Prepare(ctx, findProductsInOrderSQL, findProductsInOrderSQL); err != nil {
		return fmt.Errorf("prepare query 'FindProductsInOrder': %w", err)
	}
	if _, err := p.Prepare(ctx, insertCustomerSQL, insertCustomerSQL); err != nil {
		return fmt.Errorf("prepare query 'InsertCustomer': %w", err)
	}
	if _, err := p.Prepare(ctx, insertOrderSQL, insertOrderSQL); err != nil {
		return fmt.Errorf("prepare query 'InsertOrder': %w", err)
	}
	if _, err := p.Prepare(ctx, findOrdersByPriceSQL, findOrdersByPriceSQL); err != nil {
		return fmt.Errorf("prepare query 'FindOrdersByPrice': %w", err)
	}
	if _, err := p.Prepare(ctx, findOrdersMRRSQL, findOrdersMRRSQL); err != nil {
		return fmt.Errorf("prepare query 'FindOrdersMRR': %w", err)
	}
	return nil
}
type typeResolver struct {
	connInfo *pgtype.ConnInfo  
}
func newTypeResolver(types []pgtype.DataType) *typeResolver {
	ci := pgtype.NewConnInfo()
	for _, typ := range types {
		if txt, ok := typ.Value.(textPreferrer); ok && typ.OID != unknownOID {
			typ.Value = txt.ValueTranscoder
		}
		ci.RegisterDataType(typ)
	}
	return &typeResolver{connInfo: ci}
}
func (tr *typeResolver) findValue(name string) (uint32, pgtype.ValueTranscoder, bool) {
	typ, ok := tr.connInfo.DataTypeForName(name)
	if !ok {
		return 0, nil, false
	}
	v := pgtype.NewValue(typ.Value)
	return typ.OID, v.(pgtype.ValueTranscoder), true
}
func (tr *typeResolver) setValue(vt pgtype.ValueTranscoder, val interface{}) pgtype.ValueTranscoder {
	if err := vt.Set(val); err != nil {
		panic(fmt.Sprintf("set ValueTranscoder %T to %+v: %s", vt, val, err))
	}
	return vt
}
const createTenantSQL = `INSERT INTO tenant (tenant_id, name)
VALUES (base36_decode($1::text)::tenant_id, $2::text)
RETURNING *;`
type CreateTenantRow struct {
	TenantID int     `json:"tenant_id"`
	Rname    *string `json:"rname"`
	Name     string  `json:"name"`
}
func (q *DBQuerier) CreateTenant(ctx context.Context, key string, name string) (CreateTenantRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "CreateTenant")
	row := q.conn.QueryRow(ctx, createTenantSQL, key, name)
	var item CreateTenantRow
	if err := row.Scan(&item.TenantID, &item.Rname, &item.Name); err != nil {
		return item, fmt.Errorf("query CreateTenant: %w", err)
	}
	return item, nil
}
func (q *DBQuerier) CreateTenantBatch(batch genericBatch, key string, name string) {
	batch.Queue(createTenantSQL, key, name)
}
func (q *DBQuerier) CreateTenantScan(results pgx.BatchResults) (CreateTenantRow, error) {
	row := results.QueryRow()
	var item CreateTenantRow
	if err := row.Scan(&item.TenantID, &item.Rname, &item.Name); err != nil {
		return item, fmt.Errorf("scan CreateTenantBatch row: %w", err)
	}
	return item, nil
}
const findOrdersByCustomerSQL = `SELECT *
FROM orders
WHERE customer_id = $1;`
type FindOrdersByCustomerRow struct {
	OrderID    int32              `json:"order_id"`
	OrderDate  pgtype.Timestamptz `json:"order_date"`
	OrderTotal pgtype.Numeric     `json:"order_total"`
	CustomerID *int32             `json:"customer_id"`
}
func (q *DBQuerier) FindOrdersByCustomer(ctx context.Context, customerID int32) ([]FindOrdersByCustomerRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindOrdersByCustomer")
	rows, err := q.conn.Query(ctx, findOrdersByCustomerSQL, customerID)
	if err != nil {
		return nil, fmt.Errorf("query FindOrdersByCustomer: %w", err)
	}
	defer rows.Close()
	items := []FindOrdersByCustomerRow{}
	for rows.Next() {
		var item FindOrdersByCustomerRow
		if err := rows.Scan(&item.OrderID, &item.OrderDate, &item.OrderTotal, &item.CustomerID); err != nil {
			return nil, fmt.Errorf("scan FindOrdersByCustomer row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindOrdersByCustomer rows: %w", err)
	}
	return items, err
}
func (q *DBQuerier) FindOrdersByCustomerBatch(batch genericBatch, customerID int32) {
	batch.Queue(findOrdersByCustomerSQL, customerID)
}
func (q *DBQuerier) FindOrdersByCustomerScan(results pgx.BatchResults) ([]FindOrdersByCustomerRow, error) {
	rows, err := results.Query()
	if err != nil {
		return nil, fmt.Errorf("query FindOrdersByCustomerBatch: %w", err)
	}
	defer rows.Close()
	items := []FindOrdersByCustomerRow{}
	for rows.Next() {
		var item FindOrdersByCustomerRow
		if err := rows.Scan(&item.OrderID, &item.OrderDate, &item.OrderTotal, &item.CustomerID); err != nil {
			return nil, fmt.Errorf("scan FindOrdersByCustomerBatch row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindOrdersByCustomerBatch rows: %w", err)
	}
	return items, err
}
const findProductsInOrderSQL = `SELECT o.order_id, p.product_id, p.name
FROM orders o
  INNER JOIN order_product op USING (order_id)
  INNER JOIN product p USING (product_id)
WHERE o.order_id = $1;`
type FindProductsInOrderRow struct {
	OrderID   *int32  `json:"order_id"`
	ProductID *int32  `json:"product_id"`
	Name      *string `json:"name"`
}
func (q *DBQuerier) FindProductsInOrder(ctx context.Context, orderID int32) ([]FindProductsInOrderRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindProductsInOrder")
	rows, err := q.conn.Query(ctx, findProductsInOrderSQL, orderID)
	if err != nil {
		return nil, fmt.Errorf("query FindProductsInOrder: %w", err)
	}
	defer rows.Close()
	items := []FindProductsInOrderRow{}
	for rows.Next() {
		var item FindProductsInOrderRow
		if err := rows.Scan(&item.OrderID, &item.ProductID, &item.Name); err != nil {
			return nil, fmt.Errorf("scan FindProductsInOrder row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindProductsInOrder rows: %w", err)
	}
	return items, err
}
func (q *DBQuerier) FindProductsInOrderBatch(batch genericBatch, orderID int32) {
	batch.Queue(findProductsInOrderSQL, orderID)
}
func (q *DBQuerier) FindProductsInOrderScan(results pgx.BatchResults) ([]FindProductsInOrderRow, error) {
	rows, err := results.Query()
	if err != nil {
		return nil, fmt.Errorf("query FindProductsInOrderBatch: %w", err)
	}
	defer rows.Close()
	items := []FindProductsInOrderRow{}
	for rows.Next() {
		var item FindProductsInOrderRow
		if err := rows.Scan(&item.OrderID, &item.ProductID, &item.Name); err != nil {
			return nil, fmt.Errorf("scan FindProductsInOrderBatch row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindProductsInOrderBatch rows: %w", err)
	}
	return items, err
}
const insertCustomerSQL = `INSERT INTO customer (first_name, last_name, email)
VALUES ($1, $2, $3)
RETURNING *;`
type InsertCustomerParams struct {
	FirstName string
	LastName  string
	Email     string
}
type InsertCustomerRow struct {
	CustomerID int32  `json:"customer_id"`
	FirstName  string `json:"first_name"`
	LastName   string `json:"last_name"`
	Email      string `json:"email"`
}