func (q *DBQuerier) FindManyDeviceArrayWithNum(ctx context.Context) ([]FindManyDeviceArrayWithNumRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindManyDeviceArrayWithNum")
	rows, err := q.conn.Query(ctx, findManyDeviceArrayWithNumSQL)
	if err != nil {
		return nil, fmt.Errorf("query FindManyDeviceArrayWithNum: %w", err)
	}
	defer rows.Close()
	items := []FindManyDeviceArrayWithNumRow{}
	deviceTypesArray := q.types.newDeviceTypeArray()
	for rows.Next() {
		var item FindManyDeviceArrayWithNumRow
		if err := rows.Scan(&item.Num, deviceTypesArray); err != nil {
			return nil, fmt.Errorf("scan FindManyDeviceArrayWithNum row: %w", err)
		}
		if err := deviceTypesArray.AssignTo(&item.DeviceTypes); err != nil {
			return nil, fmt.Errorf("assign FindManyDeviceArrayWithNum row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindManyDeviceArrayWithNum rows: %w", err)
	}
	return items, err
}
FindManyDeviceArrayWithNum implements Querier.FindManyDeviceArrayWithNum.
package enums
import (
	"context"
	"fmt"
	"github.com/jackc/pgconn"
	"github.com/jackc/pgtype"
	"github.com/jackc/pgx/v4"
)
type Querier interface {
	FindAllDevices(ctx context.Context) ([]FindAllDevicesRow, error)
	FindAllDevicesBatch(batch genericBatch)
	FindAllDevicesScan(results pgx.BatchResults) ([]FindAllDevicesRow, error)
	InsertDevice(ctx context.Context, mac pgtype.Macaddr, typePg DeviceType) (pgconn.CommandTag, error)
	InsertDeviceBatch(batch genericBatch, mac pgtype.Macaddr, typePg DeviceType)
	InsertDeviceScan(results pgx.BatchResults) (pgconn.CommandTag, error)
	FindOneDeviceArray(ctx context.Context) ([]DeviceType, error)
	FindOneDeviceArrayBatch(batch genericBatch)
	FindOneDeviceArrayScan(results pgx.BatchResults) ([]DeviceType, error)
	FindManyDeviceArray(ctx context.Context) ([][]DeviceType, error)
	FindManyDeviceArrayBatch(batch genericBatch)
	FindManyDeviceArrayScan(results pgx.BatchResults) ([][]DeviceType, error)
	FindManyDeviceArrayWithNum(ctx context.Context) ([]FindManyDeviceArrayWithNumRow, error)
	FindManyDeviceArrayWithNumBatch(batch genericBatch)
	FindManyDeviceArrayWithNumScan(results pgx.BatchResults) ([]FindManyDeviceArrayWithNumRow, error)
	EnumInsideComposite(ctx context.Context) (Device, error)
	EnumInsideCompositeBatch(batch genericBatch)
	EnumInsideCompositeScan(results pgx.BatchResults) (Device, 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, findAllDevicesSQL, findAllDevicesSQL); err != nil {
		return fmt.Errorf("prepare query 'FindAllDevices': %w", err)
	}
	if _, err := p.Prepare(ctx, insertDeviceSQL, insertDeviceSQL); err != nil {
		return fmt.Errorf("prepare query 'InsertDevice': %w", err)
	}
	if _, err := p.Prepare(ctx, findOneDeviceArraySQL, findOneDeviceArraySQL); err != nil {
		return fmt.Errorf("prepare query 'FindOneDeviceArray': %w", err)
	}
	if _, err := p.Prepare(ctx, findManyDeviceArraySQL, findManyDeviceArraySQL); err != nil {
		return fmt.Errorf("prepare query 'FindManyDeviceArray': %w", err)
	}
	if _, err := p.Prepare(ctx, findManyDeviceArrayWithNumSQL, findManyDeviceArrayWithNumSQL); err != nil {
		return fmt.Errorf("prepare query 'FindManyDeviceArrayWithNum': %w", err)
	}
	if _, err := p.Prepare(ctx, enumInsideCompositeSQL, enumInsideCompositeSQL); err != nil {
		return fmt.Errorf("prepare query 'EnumInsideComposite': %w", err)
	}
	return nil
}
type Device struct {
	Mac  pgtype.Macaddr `json:"mac"`
	Type DeviceType     `json:"type"`
}
func newDeviceTypeEnum() pgtype.ValueTranscoder {
	return pgtype.NewEnumType(
		"device_type",
		[]string{
			string(DeviceTypeUndefined),
			string(DeviceTypePhone),
			string(DeviceTypeLaptop),
			string(DeviceTypeIpad),
			string(DeviceTypeDesktop),
			string(DeviceTypeIot),
		},
	)
}
type DeviceType string
const (
	DeviceTypeUndefined DeviceType = "undefined"
	DeviceTypePhone     DeviceType = "phone"
	DeviceTypeLaptop    DeviceType = "laptop"
	DeviceTypeIpad      DeviceType = "ipad"
	DeviceTypeDesktop   DeviceType = "desktop"
	DeviceTypeIot       DeviceType = "iot"
)
func (d DeviceType) String() string { return string(d) }
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
}
type compositeField struct {
	name       string                  
	typeName   string                  
	defaultVal pgtype.ValueTranscoder  
}
func (tr *typeResolver) newCompositeValue(name string, fields ...compositeField) pgtype.ValueTranscoder {
	if _, val, ok := tr.findValue(name); ok {
		return val
	}
	fs := make([]pgtype.CompositeTypeField, len(fields))
	vals := make([]pgtype.ValueTranscoder, len(fields))
	isBinaryOk := true
	for i, field := range fields {
		oid, val, ok := tr.findValue(field.typeName)
		if !ok {
			oid = unknownOID
			val = field.defaultVal
		}
		isBinaryOk = isBinaryOk && oid != unknownOID
		fs[i] = pgtype.CompositeTypeField{Name: field.name, OID: oid}
		vals[i] = val
	}
	typ, _ := pgtype.NewCompositeTypeValues(name, fs, vals)
	if !isBinaryOk {
		return textPreferrer{typ, name}
	}
	return typ
}
func (tr *typeResolver) newArrayValue(name, elemName string, defaultVal func() pgtype.ValueTranscoder) pgtype.ValueTranscoder {
	if _, val, ok := tr.findValue(name); ok {
		return val
	}
	elemOID, elemVal, ok := tr.findValue(elemName)
	elemValFunc := func() pgtype.ValueTranscoder {
		return pgtype.NewValue(elemVal).(pgtype.ValueTranscoder)
	}
	if !ok {
		elemOID = unknownOID
		elemValFunc = defaultVal
	}
	typ := pgtype.NewArrayType(name, elemOID, elemValFunc)
	if elemOID == unknownOID {
		return textPreferrer{typ, name}
	}
	return typ
}
func (tr *typeResolver) newDevice() pgtype.ValueTranscoder {
	return tr.newCompositeValue(
		"device",
		compositeField{"mac", "macaddr", &pgtype.Macaddr{}},
		compositeField{"type", "device_type", newDeviceTypeEnum()},
	)
}
func (tr *typeResolver) newDeviceTypeArray() pgtype.ValueTranscoder {
	return tr.newArrayValue("_device_type", "device_type", newDeviceTypeEnum)
}
const findAllDevicesSQL = `SELECT mac, type
FROM device;`
type FindAllDevicesRow struct {
	Mac  pgtype.Macaddr `json:"mac"`
	Type DeviceType     `json:"type"`
}
func (q *DBQuerier) FindAllDevices(ctx context.Context) ([]FindAllDevicesRow, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindAllDevices")
	rows, err := q.conn.Query(ctx, findAllDevicesSQL)
	if err != nil {
		return nil, fmt.Errorf("query FindAllDevices: %w", err)
	}
	defer rows.Close()
	items := []FindAllDevicesRow{}
	for rows.Next() {
		var item FindAllDevicesRow
		if err := rows.Scan(&item.Mac, &item.Type); err != nil {
			return nil, fmt.Errorf("scan FindAllDevices row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindAllDevices rows: %w", err)
	}
	return items, err
}
func (q *DBQuerier) FindAllDevicesBatch(batch genericBatch) {
	batch.Queue(findAllDevicesSQL)
}
func (q *DBQuerier) FindAllDevicesScan(results pgx.BatchResults) ([]FindAllDevicesRow, error) {
	rows, err := results.Query()
	if err != nil {
		return nil, fmt.Errorf("query FindAllDevicesBatch: %w", err)
	}
	defer rows.Close()
	items := []FindAllDevicesRow{}
	for rows.Next() {
		var item FindAllDevicesRow
		if err := rows.Scan(&item.Mac, &item.Type); err != nil {
			return nil, fmt.Errorf("scan FindAllDevicesBatch row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindAllDevicesBatch rows: %w", err)
	}
	return items, err
}
const insertDeviceSQL = `INSERT INTO device (mac, type)
VALUES ($1, $2);`
func (q *DBQuerier) InsertDevice(ctx context.Context, mac pgtype.Macaddr, typePg DeviceType) (pgconn.CommandTag, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "InsertDevice")
	cmdTag, err := q.conn.Exec(ctx, insertDeviceSQL, mac, typePg)
	if err != nil {
		return cmdTag, fmt.Errorf("exec query InsertDevice: %w", err)
	}
	return cmdTag, err
}
func (q *DBQuerier) InsertDeviceBatch(batch genericBatch, mac pgtype.Macaddr, typePg DeviceType) {
	batch.Queue(insertDeviceSQL, mac, typePg)
}
func (q *DBQuerier) InsertDeviceScan(results pgx.BatchResults) (pgconn.CommandTag, error) {
	cmdTag, err := results.Exec()
	if err != nil {
		return cmdTag, fmt.Errorf("exec InsertDeviceBatch: %w", err)
	}
	return cmdTag, err
}
const findOneDeviceArraySQL = `SELECT enum_range(NULL::device_type) AS device_types;`
func (q *DBQuerier) FindOneDeviceArray(ctx context.Context) ([]DeviceType, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindOneDeviceArray")
	row := q.conn.QueryRow(ctx, findOneDeviceArraySQL)
	item := []DeviceType{}
	deviceTypesArray := q.types.newDeviceTypeArray()
	if err := row.Scan(deviceTypesArray); err != nil {
		return item, fmt.Errorf("query FindOneDeviceArray: %w", err)
	}
	if err := deviceTypesArray.AssignTo(&item); err != nil {
		return item, fmt.Errorf("assign FindOneDeviceArray row: %w", err)
	}
	return item, nil
}
func (q *DBQuerier) FindOneDeviceArrayBatch(batch genericBatch) {
	batch.Queue(findOneDeviceArraySQL)
}
func (q *DBQuerier) FindOneDeviceArrayScan(results pgx.BatchResults) ([]DeviceType, error) {
	row := results.QueryRow()
	item := []DeviceType{}
	deviceTypesArray := q.types.newDeviceTypeArray()
	if err := row.Scan(deviceTypesArray); err != nil {
		return item, fmt.Errorf("scan FindOneDeviceArrayBatch row: %w", err)
	}
	if err := deviceTypesArray.AssignTo(&item); err != nil {
		return item, fmt.Errorf("assign FindOneDeviceArray row: %w", err)
	}
	return item, nil
}
const findManyDeviceArraySQL = `SELECT enum_range('ipad'::device_type, 'iot'::device_type) AS device_types
UNION ALL
SELECT enum_range(NULL::device_type) AS device_types;`
func (q *DBQuerier) FindManyDeviceArray(ctx context.Context) ([][]DeviceType, error) {
	ctx = context.WithValue(ctx, "pggen_query_name", "FindManyDeviceArray")
	rows, err := q.conn.Query(ctx, findManyDeviceArraySQL)
	if err != nil {
		return nil, fmt.Errorf("query FindManyDeviceArray: %w", err)
	}
	defer rows.Close()
	items := [][]DeviceType{}
	deviceTypesArray := q.types.newDeviceTypeArray()
	for rows.Next() {
		var item []DeviceType
		if err := rows.Scan(deviceTypesArray); err != nil {
			return nil, fmt.Errorf("scan FindManyDeviceArray row: %w", err)
		}
		if err := deviceTypesArray.AssignTo(&item); err != nil {
			return nil, fmt.Errorf("assign FindManyDeviceArray row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindManyDeviceArray rows: %w", err)
	}
	return items, err
}
func (q *DBQuerier) FindManyDeviceArrayBatch(batch genericBatch) {
	batch.Queue(findManyDeviceArraySQL)
}
func (q *DBQuerier) FindManyDeviceArrayScan(results pgx.BatchResults) ([][]DeviceType, error) {
	rows, err := results.Query()
	if err != nil {
		return nil, fmt.Errorf("query FindManyDeviceArrayBatch: %w", err)
	}
	defer rows.Close()
	items := [][]DeviceType{}
	deviceTypesArray := q.types.newDeviceTypeArray()
	for rows.Next() {
		var item []DeviceType
		if err := rows.Scan(deviceTypesArray); err != nil {
			return nil, fmt.Errorf("scan FindManyDeviceArrayBatch row: %w", err)
		}
		if err := deviceTypesArray.AssignTo(&item); err != nil {
			return nil, fmt.Errorf("assign FindManyDeviceArray row: %w", err)
		}
		items = append(items, item)
	}
	if err := rows.Err(); err != nil {
		return nil, fmt.Errorf("close FindManyDeviceArrayBatch rows: %w", err)
	}
	return items, err
}
const findManyDeviceArrayWithNumSQL = `SELECT 1 AS num, enum_range('ipad'::device_type, 'iot'::device_type) AS device_types
UNION ALL
SELECT 2 as num, enum_range(NULL::device_type) AS device_types;`
type FindManyDeviceArrayWithNumRow struct {
	Num         *int32       `json:"num"`
	DeviceTypes []DeviceType `json:"device_types"`
}