config

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PluginVersion = "v0.8.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Package                     string              `json:"package"                                  yaml:"package"`
	SqlDriver                   SQLDriver           `json:"sql_driver"                               yaml:"sql_driver"`
	ModelType                   ModelType           `json:"model_type"                               yaml:"model_type"`
	Initialisms                 *[]string           `json:"initialisms,omitempty"                    yaml:"initialisms,omitempty"`
	EmitExactTableNames         bool                `json:"emit_exact_table_names"                   yaml:"emit_exact_table_names"`
	EmitClasses                 bool                `json:"emit_classes"                             yaml:"emit_classes"`
	InflectionExcludeTableNames []string            `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names,omitempty"`
	OmitUnusedModels            bool                `json:"omit_unused_models"                       yaml:"omit_unused_models"`
	OmitTypecheckingBlock       bool                `json:"omit_typechecking_block"                  yaml:"omit_typechecking_block"`
	QueryParameterLimit         *int                `json:"query_parameter_limit,omitempty"          yaml:"query_parameter_limit"`
	OmitKwargsLimit             int                 `json:"omit_kwargs_limit,omitempty"              yaml:"omit_kwargs_limit"`
	EmitInitFile                *bool               `json:"emit_init_file"                           yaml:"emit_init_file"`
	EmitDocstrings              DocstringConvention `json:"docstrings"                               yaml:"docstrings"`
	EmitDocstringsSQL           *bool               `json:"docstrings_emit_sql"                      yaml:"docstrings_emit_sql"`
	Speedups                    bool                `json:"speedups"                                 yaml:"speedups"`
	Overrides                   []Override          `json:"overrides,omitempty"                      yaml:"overrides,omitempty"`
	Converters                  []Converter         `json:"converters,omitempty"                     yaml:"converters,omitempty"`

	Debug bool `json:"debug" yaml:"debug"`

	IndentChar          string `json:"indent_char"            yaml:"indent_char"`
	CharsPerIndentLevel int    `json:"chars_per_indent_level" yaml:"chars_per_indent_level"`

	InitialismsMap map[string]struct{} `json:"-" yaml:"-"`
}

func NewConfig

func NewConfig(req *plugin.GenerateRequest) (*Config, error)

func (*Config) IsOverQueryParameterLimit

func (config *Config) IsOverQueryParameterLimit(num int) bool

IsOverQueryParameterLimit reports whether a query's parameters should be bundled into a Params class. This is opt-in: it only applies when query_parameter_limit is explicitly set to a non-negative value and the query has more parameters than the limit.

type Converter added in v0.6.0

type Converter struct {
	Name   string         `json:"name"    yaml:"name"`
	PyType OverridePyType `json:"py_type" yaml:"py_type"`
	ToDB   string         `json:"to_db"   yaml:"to_db"`
	FromDB string         `json:"from_db" yaml:"from_db"`
}

Converter names a pair of user functions that translate a column value between its Python type and the type the driver expects. Both are dotted paths; the module is imported and the function called fully qualified.

type DocstringConvention

type DocstringConvention string
const (
	DocstringConventionNone   DocstringConvention = "none"
	DocstringConventionGoogle DocstringConvention = "google"
	DocstringConventionNumpy  DocstringConvention = "numpy"
	DocstringConventionPEP257 DocstringConvention = "pep257"
)

func (DocstringConvention) Valid

func (ds DocstringConvention) Valid() bool

type ModelType

type ModelType string
const (
	ModelTypeDataclass ModelType = "dataclass"
	ModelTypeAttrs     ModelType = "attrs"
	ModelTypeMsgspec   ModelType = "msgspec"
	ModelTypePydantic  ModelType = "pydantic"
)

func (ModelType) Valid

func (modelType ModelType) Valid() bool

type Override

type Override struct {
	PyType OverridePyType `json:"py_type" yaml:"py_type"`

	// Converter names an entry in the top-level converters list, supplying
	// both the Python type and the functions converting to and from it.
	Converter string     `json:"converter" yaml:"converter"`
	Resolved  *Converter `json:"-"         yaml:"-"`

	// DBType matches the SQL data type exactly, e.g. "text" or "pg_catalog.int4".
	DBType string `json:"db_type" yaml:"db_type"`

	// Column matches a fully qualified column name, e.g. "authors.name".
	Column string `json:"column" yaml:"column"`

	ColumnName   *pattern.Match `json:"-" yaml:"-"`
	TableCatalog *pattern.Match `json:"-" yaml:"-"`
	TableSchema  *pattern.Match `json:"-" yaml:"-"`
	TableRel     *pattern.Match `json:"-" yaml:"-"`
}

Override replaces the default Python type of columns matched either by SQL type (DBType) or by a column pattern ("[catalog.][schema.]table.column", wildcards supported).

func (*Override) Matches

func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool

Matches reports whether the override's table pattern matches the identifier.

type OverridePyType

type OverridePyType struct {
	Import  string `json:"import"  yaml:"import"`
	Type    string `json:"type"    yaml:"type"`
	Package string `json:"package" yaml:"package"`
}

OverridePyType describes the Python type that replaces the default mapping. Import is the module to import (e.g. "collections"); Type is the type expression used in annotations (e.g. "UserString" or "collections.UserString"); Package is the name imported from Import ("from <import> import <package>") - if empty, Import is imported as a plain module ("import <import>").

type SQLDriver

type SQLDriver string
const (
	SQLDriverSQLite       SQLDriver = "sqlite3"
	SQLDriverAioSQLite    SQLDriver = "aiosqlite"
	SQLDriverAsyncpg      SQLDriver = "asyncpg"
	SQLDriverPsycopgAsync SQLDriver = "psycopg_async"
	SQLDriverPsycopgSync  SQLDriver = "psycopg_sync"
	SQLDriverTursoSync    SQLDriver = "turso_sync"
	SQLDriverTursoAsync   SQLDriver = "turso_async"
)

func (SQLDriver) IsPsycopg added in v0.7.0

func (dr SQLDriver) IsPsycopg() bool

IsPsycopg reports whether the driver is one of the two psycopg flavors, which share the psycopg module, the %(pN)s placeholder rewrite, and the LiteralString query-text contract.

func (SQLDriver) IsTurso added in v0.8.0

func (dr SQLDriver) IsTurso() bool

IsTurso reports whether the driver is one of the two pyturso flavors, which share inline type conversion in both directions - pyturso has no adapter/converter registry and binds only None, numbers, strings, and bytes.

func (SQLDriver) String

func (dr SQLDriver) String() string

func (SQLDriver) Validate

func (dr SQLDriver) Validate(engine string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL