core

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package core Auto-generated using python; DO NOT EDIT py 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)]

Index

Constants

View Source
const (
	ModelTypeDataclass = "dataclass"
	ModelTypeAttrs     = "attrs"
	ModelTypeMsgspec   = "msgspec"
)
View Source
const (
	DocstringConventionNone   = "none"
	DocstringConventionGoogle = "google"
	DocstringConventionNumpy  = "numpy"
	DocstringConventionPEP257 = "pep257"
)
View Source
const PluginVersion = "v0.4.5"

Variables

This section is empty.

Functions

func ColumnName

func ColumnName(c *plugin.Column, pos int) string

func EnumReplace

func EnumReplace(value string) string

EnumReplace removes all non ident symbols (all but letters, numbers and underscore) and returns valid ident name for provided name.

func Escape

func Escape(s string) string

func IsAnyQueryMany added in v0.4.0

func IsAnyQueryMany(queries []Query) bool

func IsInMultipleMaps added in v0.4.0

func IsInMultipleMaps[K comparable, V any](search K, maps ...map[K]V) bool

func IsReserved

func IsReserved(s string) bool

func ModelName

func ModelName(enumName string, schemaName string, conf *Config) string

func ParamName

func ParamName(p *plugin.Parameter) string

func SQLToPyFileName

func SQLToPyFileName(s string) string

func SnakeToCamel

func SnakeToCamel(s string, conf *Config) string

func SplitLines added in v0.4.0

func SplitLines(s string) []string

func UpperSnakeCase

func UpperSnakeCase(s string) string

func ValidateConf

func ValidateConf(conf *Config, engine string) error

Types

type Column

type Column struct {
	Name    string // CamelCased name for Go
	DBName  string // Name as used in the DB
	Type    PyType
	Comment string
	Column  *plugin.Column
	// EmbedFields contains the embedded fields that require scanning.
	EmbedFields []Column
}

type Config

type Config struct {
	Package                     string        `json:"package" yaml:"package"`
	SqlDriver                   SQLDriverType `json:"sql_driver" yaml:"sql_driver"`
	ModelType                   string        `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         *int32        `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"`
	OmitKwargsLimit             *int32        `json:"omit_kwargs_limit,omitempty" yaml:"omit_kwargs_limit"`
	EmitInitFile                *bool         `json:"emit_init_file" yaml:"emit_init_file"`
	EmitDocstrings              *string       `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"`

	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:"-"`
	Async          bool
}

func ParseConfig

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

type Constant

type Constant struct {
	Name  string
	Type  string
	Value string
}

type Enum

type Enum struct {
	Name      string
	Comment   string
	Constants []Constant
}

type FunctionArg added in v0.4.0

type FunctionArg struct {
	Name           string
	Type           string
	FunctionFormat string
}

type Importer

type Importer struct {
	Tables  []Table
	Queries []Query
	Enums   []Enum
	C       *Config
}

func (*Importer) Imports

func (i *Importer) Imports(fileName string) ([]string, []string, []string)

type Override added in v0.4.2

type Override struct {
	// name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID`
	PyType OverridePyType `json:"py_type" yaml:"py_type"`

	// fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID`
	DBType string `json:"db_type" yaml:"db_type"`

	// fully qualified name of the column, e.g. `accounts.id`
	Column string `json:"column" yaml:"column"`

	ColumnName    *pattern.Match `json:"-"`
	TableCatalog  *pattern.Match `json:"-"`
	TableSchema   *pattern.Match `json:"-"`
	TableRel      *pattern.Match `json:"-"`
	PyImportPath  string         `json:"-"`
	PyPackageName string         `json:"-"`
	PyTypeName    string         `json:"-"`
	PyBasicType   bool           `json:"-"`
}

func (*Override) Matches added in v0.4.2

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

type OverridePyType added in v0.4.2

type OverridePyType struct {
	Import  string `json:"import" yaml:"import"`
	Name    string `json:"type" yaml:"type"`
	Package string `json:"package" yaml:"package"`
	Spec    string `json:"-"`
	BuiltIn bool   `json:"-"`
}

type ParsedOverridePyType added in v0.4.2

type ParsedOverridePyType struct {
	ImportPath  string
	TypeName    string
	PackageName string
	BasicType   bool
}

type PyType

type PyType struct {
	SqlType     string
	Type        string
	DefaultType string
	IsList      bool
	IsNullable  bool
	IsEnum      bool
	IsOverride  bool
	Override    *Override
}

func TableUses added in v0.4.0

func TableUses(name string, s Table) (bool, PyType)

func (*PyType) DoConversion added in v0.4.2

func (p *PyType) DoConversion(conversion typeConversion.TypeDoTypeConversion) bool

func (*PyType) DoOverride added in v0.4.2

func (p *PyType) DoOverride() bool

type Query

type Query struct {
	Cmd          string
	Comments     []string
	MethodName   string
	FuncName     string
	FieldName    string
	ConstantName string
	SQL          string
	SourceName   string
	Ret          QueryValue
	Args         []QueryValue

	// Used for :copyfrom
	Table *plugin.Identifier
}

func (Query) HasRetType

func (q Query) HasRetType() bool

type QueryValue

type QueryValue struct {
	Emit   bool
	Name   string
	DBName string // The name of the field in the database. Only set if Struct==nil.
	Table  *Table
	Typ    PyType

	// Column is kept so late in the generation process around to differentiate
	// between mysql slices and pg arrays
	Column *plugin.Column
}

func (QueryValue) EmitStruct

func (v QueryValue) EmitStruct() bool

func (QueryValue) IsEmpty

func (v QueryValue) IsEmpty() bool

func (QueryValue) IsStruct

func (v QueryValue) IsStruct() bool

func (QueryValue) Type

func (v QueryValue) Type() string

type SQLDriverType

type SQLDriverType string
const (
	SQLDriverSQLite    SQLDriverType = "sqlite3"
	SQLDriverAioSQLite SQLDriverType = "aiosqlite"
	SQLDriverAsyncpg   SQLDriverType = "asyncpg"
)

func (*SQLDriverType) String

func (dr *SQLDriverType) String() string

type Table

type Table struct {
	Table   *plugin.Identifier
	Name    string
	Columns []Column
	Comment string
}

Jump to

Keyboard shortcuts

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