Documentation
¶
Index ¶
- func PsycopgJSONTypesReturned(queries []model.Query) []string
- type AsyncpgDriver
- func (d *AsyncpgDriver) ConnType() string
- func (d *AsyncpgDriver) ConvertsInline(sqlType string) bool
- func (d *AsyncpgDriver) IsAsync() bool
- func (d *AsyncpgDriver) Name() string
- func (d *AsyncpgDriver) NeedsConversion(sqlType string) bool
- func (d *AsyncpgDriver) SupportsCommand(cmd string) bool
- func (d *AsyncpgDriver) TypeCheckingHook() []string
- func (d *AsyncpgDriver) WriteConversionSetup(_ *writer.CodeWriter, _ *config.Config, _ []model.Query) bool
- func (d *AsyncpgDriver) WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int)
- func (d *AsyncpgDriver) WriteQueryResultsClass(body *writer.CodeWriter) string
- type Driver
- type RowBuilder
- func (rb *RowBuilder) WriteDecodeHook(body *writer.CodeWriter, indent int, query model.Query, resultType string) string
- func (rb *RowBuilder) WriteScalarReturn(body *writer.CodeWriter, indent int, ret model.QueryValue)
- func (rb *RowBuilder) WriteStructReturn(body *writer.CodeWriter, indent int, ret model.QueryValue)
- type SqliteConversionUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PsycopgJSONTypesReturned ¶ added in v0.7.0
PsycopgJSONTypesReturned collects the distinct json/jsonb type names a module's queries return, which decide the loader registrations.
Types ¶
type AsyncpgDriver ¶
type AsyncpgDriver struct {
// contains filtered or unexported fields
}
AsyncpgDriver generates Python code for the asyncpg (async PostgreSQL) driver.
func (*AsyncpgDriver) ConnType ¶
func (d *AsyncpgDriver) ConnType() string
ConnType returns "ConnectionLike".
func (*AsyncpgDriver) ConvertsInline ¶
func (d *AsyncpgDriver) ConvertsInline(sqlType string) bool
ConvertsInline reports whether a SQL type is converted inline; asyncpg converts everything inline (no registration mechanism).
func (*AsyncpgDriver) NeedsConversion ¶
func (d *AsyncpgDriver) NeedsConversion(sqlType string) bool
NeedsConversion reports whether a SQL type needs runtime conversion for asyncpg.
func (*AsyncpgDriver) SupportsCommand ¶
func (d *AsyncpgDriver) SupportsCommand(cmd string) bool
SupportsCommand returns if the driver supports the command.
func (*AsyncpgDriver) TypeCheckingHook ¶
func (d *AsyncpgDriver) TypeCheckingHook() []string
TypeCheckingHook returns the ConnectionLike type alias. The PEP 695 form is lazy by design, which matters here: asyncpg.Connection[...] is a stub-only generic that raises TypeError when subscripted at runtime, and with omit_typechecking_block the alias is emitted at module level where it actually executes.
func (*AsyncpgDriver) WriteConversionSetup ¶
func (d *AsyncpgDriver) WriteConversionSetup(_ *writer.CodeWriter, _ *config.Config, _ []model.Query) bool
WriteConversionSetup is a no-op for asyncpg.
func (*AsyncpgDriver) WriteQueryFunc ¶
func (d *AsyncpgDriver) WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int)
func (*AsyncpgDriver) WriteQueryResultsClass ¶
func (d *AsyncpgDriver) WriteQueryResultsClass(body *writer.CodeWriter) string
WriteQueryResultsClass writes the async QueryResults class for asyncpg :many queries.
type Driver ¶
type Driver interface {
// Name returns the Python module name (e.g., "asyncpg", "aiosqlite", "sqlite3").
Name() string
// ConnType returns the Python type annotation for the connection parameter.
ConnType() string
// SupportsCommand returns if the driver supports the command.
SupportsCommand(cmd string) bool
// IsAsync reports whether this driver uses async/await.
IsAsync() bool
// NeedsConversion reports whether a SQL type needs explicit Python-side conversion,
// meaning the type's module must be imported at runtime (not TYPE_CHECKING-only).
NeedsConversion(sqlType string) bool
// ConvertsInline reports whether values of this SQL type are converted inline in
// generated decode code. Drivers that register converters instead return false.
// Must stay in sync with the RowBuilder's conversion check.
ConvertsInline(sqlType string) bool
// WriteConversionSetup writes module-level type conversion setup (e.g. sqlite
// adapter/converter registration) and reports whether anything was written.
WriteConversionSetup(body *writer.CodeWriter, config *config.Config, queries []model.Query) bool
// WriteQueryFunc writes the Python function body for a single query.
WriteQueryFunc(body *writer.CodeWriter, config *config.Config, query model.Query, indent int)
// WriteQueryResultsClass writes the QueryResults helper class for :many queries.
// Returns the class name (typically "QueryResults").
WriteQueryResultsClass(w *writer.CodeWriter) string
// TypeCheckingHook returns additional lines to emit in the TYPE_CHECKING
// block. The lines must also be runtime-safe: with omit_typechecking_block
// they are emitted at module level and actually execute.
TypeCheckingHook() []string
}
type RowBuilder ¶
type RowBuilder struct {
// contains filtered or unexported fields
}
RowBuilder generates Python code that constructs a model instance from a database row. It handles embeds, nullable conversions, and overrides uniformly across all drivers.
func (*RowBuilder) WriteDecodeHook ¶
func (rb *RowBuilder) WriteDecodeHook(body *writer.CodeWriter, indent int, query model.Query, resultType string) string
WriteDecodeHook writes a _decode_hook function for :many queries or returns "operator.itemgetter(0)" for simple non-converted scalar returns. The blank lines around the nested def match ruff format's layout.
func (*RowBuilder) WriteScalarReturn ¶
func (rb *RowBuilder) WriteScalarReturn(body *writer.CodeWriter, indent int, ret model.QueryValue)
WriteScalarReturn writes the return statement for a non-struct :one query.
func (*RowBuilder) WriteStructReturn ¶
func (rb *RowBuilder) WriteStructReturn(body *writer.CodeWriter, indent int, ret model.QueryValue)
WriteStructReturn writes "return ModelType(col1=row[0], col2=row[1], ...)" handling embeds, nullable wrapping, and type conversions. Constructions that would exceed the line limit are exploded with magic trailing commas.
type SqliteConversionUsage ¶
type SqliteConversionUsage struct {
// contains filtered or unexported fields
}
SqliteConversionUsage lists the conversion specs a module's queries need, in canonical emission order, split by direction: parameters need a registered adapter (Python value -> SQL), returns need a registered converter (SQL value -> Python). Registering only what is needed matters because sqlite3 converters are global: an unnecessary register_converter would change what overridden return columns receive under PARSE_DECLTYPES.
func SqliteConversionsUsed ¶
func SqliteConversionsUsed(queries []model.Query) SqliteConversionUsage
SqliteConversionsUsed collects the conversion specs used by the queries. Overridden RETURN columns need no converter - they are converted inline with the override type, and registering one anyway would hand the override constructor an already-converted value. Overridden PARAMS do need the adapter: convertParamExpr converts them back to their DefaultType before they reach the driver.
func (SqliteConversionUsage) Any ¶
func (u SqliteConversionUsage) Any() bool
Any reports whether at least one adapter or converter must be registered.
func (SqliteConversionUsage) RuntimeModules ¶
func (u SqliteConversionUsage) RuntimeModules(speedups bool) map[string]struct{}
RuntimeModules returns the Python modules the emitted conversion setup references at runtime: register_adapter needs the adapted type's module, and converter bodies reference their type's module unless the speedups variant (which references only ciso8601) replaces them. Builtin types (bool, memoryview) need no import.
func (SqliteConversionUsage) SpeedupConverterUsed ¶
func (u SqliteConversionUsage) SpeedupConverterUsed() bool
SpeedupConverterUsed reports whether any needed converter has a speedups variant - i.e. whether the generated module references ciso8601 when the speedups option is enabled.