config

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config loads and validates the db-catalyst configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Enabled bool
	Dir     string
}

Cache is the normalized cache configuration forwarded to the pipeline.

type CacheConfig

type CacheConfig struct {
	Enabled bool   `toml:"enabled"`
	Dir     string `toml:"dir"`
}

CacheConfig captures caching configuration for incremental builds.

type CodegenPluginConfig added in v0.11.0

type CodegenPluginConfig struct {
	Plugin  string         `toml:"plugin"`
	Out     string         `toml:"out"`
	Options map[string]any `toml:"options"`
}

CodegenPluginConfig routes the IR to a named plugin via a [[codegen]] entry, writing the plugin's files rooted at Out. Options is an opaque table passed to the plugin verbatim as JSON.

type ColumnOverride

type ColumnOverride struct {
	Column string        `toml:"column"`
	GoType GoTypeDetails `toml:"go_type"`
}

ColumnOverride defines column-specific type overrides (sqlc compatibility). The go_type field can be either a simple string or a complex object.

type Config

type Config struct {
	Package       string            `toml:"package"`
	Out           string            `toml:"out"`
	ModelsPackage string            `toml:"models_package"`
	ModelsImport  string            `toml:"models_import"`
	Language      Language          `toml:"language"`
	Database      Database          `toml:"database"`
	SQLiteDriver  Driver            `toml:"sqlite_driver"`
	Schemas       []string          `toml:"schemas"`
	Queries       []string          `toml:"queries"`
	CustomTypes   CustomTypesConfig `toml:"custom_types"`
	// Overrides are parsed separately to handle flexible go_type formats
	Generation GenerationOptions `toml:"generation"`
	// Rename is the [rename] table: exact SQL name → exported Go identifier.
	Rename          map[string]string     `toml:"rename"`
	PreparedQueries PreparedQueriesConfig `toml:"prepared_queries"`
	Cache           CacheConfig           `toml:"cache"`
	Verify          VerifyConfig          `toml:"verify"`
	Migrations      MigrationsConfig      `toml:"migrations"`
	Vet             VetConfig             `toml:"vet"`
	Plugins         []PluginConfig        `toml:"plugins"`
	Codegen         []CodegenPluginConfig `toml:"codegen"`
}

Config mirrors the expected db-catalyst TOML schema.

type CustomTypeMapping

type CustomTypeMapping struct {
	CustomType string `toml:"custom_type"`
	SQLiteType string `toml:"sqlite_type"`
	GoType     string `toml:"go_type"`
	GoImport   string `toml:"go_import"`
	GoPackage  string `toml:"go_package"`
	Pointer    bool   `toml:"pointer"`
	// JSON, when true, binds the column to GoType as a JSON document: generated
	// code scans the column into a []byte holder and json.Unmarshal's it into the
	// struct, and json.Marshal's the struct back to []byte when binding it as a
	// query parameter. This round-trips a JSON/JSONB/TEXT column to a named Go
	// struct. It is additive: mappings without json=true are unchanged.
	JSON bool `toml:"json"`
}

CustomTypeMapping defines how a custom type maps to SQLite and Go types.

type CustomTypesConfig

type CustomTypesConfig struct {
	Mappings []CustomTypeMapping `toml:"mapping"`
}

CustomTypesConfig captures custom type mappings.

type Database

type Database string

Database identifies the target database dialect.

const (
	// DatabaseSQLite targets SQLite.
	DatabaseSQLite Database = "sqlite"
	// DatabaseTurso targets Turso Database (the Rust rewrite of SQLite,
	// formerly Limbo). It is SQLite-compatible at the SQL and file-format
	// level, so it reuses the SQLite schema parser and type mapping, differing
	// only in the database/sql driver identity and native vector columns.
	DatabaseTurso Database = "turso"
	// DatabasePostgreSQL targets PostgreSQL.
	DatabasePostgreSQL Database = "postgresql"
	// DatabaseMySQL targets MySQL.
	DatabaseMySQL Database = "mysql"
	// DatabaseDuckDB targets DuckDB. DuckDB is an in-process analytical
	// database whose DDL is compatible with the SQLite parser for the common
	// subset. Static codegen is fully supported; no live DuckDB driver is
	// required at code-generation time.
	DatabaseDuckDB Database = "duckdb"
	// DatabaseClickHouse targets ClickHouse. ClickHouse DDL uses functional
	// type wrappers (Nullable(T), Array(T), Map(K,V), LowCardinality(T)) and
	// requires an ENGINE clause on every CREATE TABLE. The ENGINE clause is
	// stripped by the ClickHouse parser preprocessor before delegating to the
	// SQLite parser. Static codegen is fully supported; no live ClickHouse
	// connection is required at code-generation time.
	DatabaseClickHouse Database = "clickhouse"
)

type DatabaseTypeOverride

type DatabaseTypeOverride struct {
	DatabaseType string `toml:"db_type"`
	GoType       string `toml:"go_type"`
}

DatabaseTypeOverride defines db_type to go_type mappings (sqlc compatibility).

type Driver

type Driver string

Driver identifies the SQLite driver implementation to target.

const (
	// DriverModernC targets modernc.org/sqlite.
	DriverModernC Driver = "modernc"
	// DriverMattN targets github.com/mattn/go-sqlite3.
	DriverMattN Driver = "mattn"
)

type GenerationOptions

type GenerationOptions struct {
	EmitEmptySlices     bool   `toml:"emit_empty_slices"`
	EmitPreparedQueries bool   `toml:"emit_prepared_queries"`
	EmitJSONTags        bool   `toml:"emit_json_tags"`
	EmitPointersForNull bool   `toml:"emit_pointers_for_null"`
	SQLDialect          string `toml:"sql_dialect"`
	// EmitDBTags adds a db:"<column_name>" struct tag alongside any json tag.
	// Default false reproduces the pre-G7 output (no db tags).
	EmitDBTags bool `toml:"emit_db_tags"`
	// JSONTagsCaseStyle controls the casing of json struct-tag values:
	// "snake", "camel", "pascal", or "none" (omit json tags entirely). The empty
	// default reproduces today's exact json tags so existing goldens are unchanged.
	JSONTagsCaseStyle string `toml:"json_tags_case_style"`
	// EmitResultStructPointers makes :one return *Row and :many return []*Row.
	// Default false keeps value (non-pointer) result returns.
	EmitResultStructPointers bool `toml:"emit_result_struct_pointers"`
	// EmitParamsStructPointers passes the grouped <Method>Params argument as a
	// *<Method>Params. Default false keeps the value argument.
	EmitParamsStructPointers bool `toml:"emit_params_struct_pointers"`
	// EmitInterface toggles generation of the Querier interface (querier.gen.go).
	// db-catalyst defaults to emitting the interface (unlike sqlc, whose default is
	// false), so an unset/nil value is treated as true; emit_interface = false
	// suppresses the file. It is a *bool so an explicit false is distinguishable
	// from an omitted key.
	EmitInterface *bool `toml:"emit_interface"`
	// Initialisms renders SQL-derived Go identifiers with the golint/sqlc
	// initialism table (user_id → UserID, url_suffix → URLSuffix). Default
	// false keeps the legacy casing (UserId) so existing output is unchanged.
	Initialisms bool `toml:"initialisms"`
}

GenerationOptions captures additional generation options.

type GoTypeDetails

type GoTypeDetails struct {
	Import  string `toml:"import"`
	Package string `toml:"package"`
	Type    string `toml:"type"`
	Pointer bool   `toml:"pointer"`
}

GoTypeDetails captures complex go_type configuration (sqlc compatibility). It can unmarshal from either a string or a map.

func (*GoTypeDetails) UnmarshalTOML added in v0.11.0

func (g *GoTypeDetails) UnmarshalTOML(data any) error

UnmarshalTOML implements custom TOML unmarshaling for GoTypeDetails. This handles both formats:

  • Simple: go_type = "string"
  • Complex: go_type = { import = "...", package = "...", type = "..." }

type JobPlan

type JobPlan struct {
	Package             string
	Out                 string
	Language            Language
	Database            Database
	SQLiteDriver        Driver
	Schemas             []string
	Queries             []string
	CustomTypes         []CustomTypeMapping
	ColumnOverrides     map[string]ColumnOverride
	EmitJSONTags        bool
	EmitPointersForNull bool
	// EmitDBTags adds db:"<column>" struct tags (G7). Default false.
	EmitDBTags bool
	// JSONTagsCaseStyle controls json tag value casing (G7): "snake", "camel",
	// "pascal", "none", or "" for the unchanged default.
	JSONTagsCaseStyle string
	// EmitResultStructPointers makes :one return *Row and :many []*Row (G7).
	EmitResultStructPointers bool
	// EmitParamsStructPointers passes <Method>Params as a pointer (G7).
	EmitParamsStructPointers bool
	// EmitInterface controls whether the Querier interface (querier.gen.go) is
	// generated (G7). Defaults to true.
	EmitInterface bool
	// Initialisms applies the golint/sqlc initialism table to SQL-derived Go
	// identifiers (issue #4). Default false keeps legacy casing.
	Initialisms bool
	// Rename maps exact SQL names (column/table tokens, e.g. "ip_address") to
	// the exported Go identifier to emit for them (e.g. "IPAddress"). Entries
	// win over Initialisms and apply regardless of that flag (issue #4).
	Rename          map[string]string
	PreparedQueries PreparedQueries
	SQLDialect      string
	Cache           Cache
	Verify          VerifyConfig
	Vet             VetConfig
	// ModelsPackage, when non-empty, splits the generated table-model structs
	// into a separate Go sub-package named (and sub-directory placed) under
	// this value, relative to Out. Empty keeps the single-package layout.
	ModelsPackage string
	// ModelsImport is the full Go import path of the models sub-package. It is
	// required whenever ModelsPackage is set so the main package can import the
	// split models deterministically without reading go.mod.
	ModelsImport string
	// Migrations controls migration-file awareness (goose, dbmate,
	// golang-migrate). An empty Format defaults to "auto" detection.
	Migrations MigrationsConfig
	// Plugins declares WASM codegen plugins (RFC 0002). Empty when no plugin is
	// configured, in which case generation is byte-identical to the no-plugin path.
	Plugins []PluginConfig
	// Codegen routes the IR to named plugins. Empty when no plugin is configured.
	Codegen []CodegenPluginConfig
}

JobPlan is the fully-resolved configuration used by downstream stages.

type Language

type Language string

Language identifies the target programming language for code generation.

const (
	// LanguageGo generates Go code.
	LanguageGo Language = "go"
	// LanguageRust generates Rust code.
	LanguageRust Language = "rust"
	// LanguageTypeScript generates TypeScript code.
	LanguageTypeScript Language = "typescript"
)

type LoadOptions

type LoadOptions struct {
	Strict   bool
	Resolver *fileset.Resolver
	// Logger receives warning messages. If nil, warnings are only added to Result.Warnings.
	Logger logging.Logger
}

LoadOptions tunes config loading behavior.

type MigrationsConfig added in v0.11.0

type MigrationsConfig struct {
	Format string `toml:"format"`
}

MigrationsConfig configures migration-file awareness. When Format is empty or "auto", the pipeline detects the format from each file's content and path. Set it explicitly to "goose", "dbmate", "golang-migrate", or "plain" to override detection.

type PluginConfig added in v0.11.0

type PluginConfig struct {
	Name string   `toml:"name"`
	WASM WASMSpec `toml:"wasm"`
}

PluginConfig declares a named WASM codegen plugin via a [[plugins]] entry. The Name is referenced by [[codegen]] entries.

type PreparedQueries

type PreparedQueries struct {
	Enabled         bool
	Metrics         bool
	ThreadSafe      bool
	EmitEmptySlices bool
}

PreparedQueries is the normalized configuration forwarded to the pipeline.

type PreparedQueriesConfig

type PreparedQueriesConfig struct {
	Enabled         bool `toml:"enabled"`
	Metrics         bool `toml:"metrics"`
	ThreadSafe      bool `toml:"thread_safe"`
	EmitEmptySlices bool `toml:"emit_empty_slices"`
}

PreparedQueriesConfig captures optional prepared statement generation settings.

type Result

type Result struct {
	Plan     JobPlan
	Warnings []string
}

Result wraps a loaded job plan alongside any non-fatal warnings.

func Load

func Load(path string, opts LoadOptions) (Result, error)

Load reads, validates, and resolves a db-catalyst configuration file.

type VerifyConfig added in v0.11.0

type VerifyConfig struct {
	Enabled bool   `toml:"enabled"`
	Engine  string `toml:"engine"`  // "sqlite" (default), "postgres"/"postgresql", or "mysql"
	Cache   string `toml:"cache"`   // offline cache path; default db-catalyst.verified.json
	Require bool   `toml:"require"` // if true, stale/missing cache fails generate
	// DSN is the data-source name used for PostgreSQL and MySQL verifiers.
	// Required when engine is "postgres", "postgresql", or "mysql".
	// May also be supplied via the DB_CATALYST_VERIFY_DSN environment variable;
	// the environment variable takes precedence over this field.
	DSN string `toml:"dsn"`
}

VerifyConfig configures the optional live-verification tier.

type VetConfig added in v0.11.0

type VetConfig struct {
	// Disabled is a list of rule names to suppress. An empty slice enables all rules.
	Disabled []string `toml:"disabled"`
}

VetConfig configures the optional query-lint engine (db-catalyst vet).

type WASMSpec added in v0.11.0

type WASMSpec struct {
	Path   string `toml:"path"`
	URL    string `toml:"url"`
	SHA256 string `toml:"sha256"`
}

WASMSpec locates a plugin's WebAssembly module: either a local Path or a remote URL pinned by SHA256 (RFC 0002 §4.3). Exactly one source is set.

Jump to

Keyboard shortcuts

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