Documentation
¶
Index ¶
- Constants
- Variables
- func FullVersionInfo() string
- func IsVersionCompatible(required string) bool
- func SetBuildInfo(commit, date, goVersion string)
- func VersionInfo() string
- type AutoMigrateOptions
- type Column
- type ColumnDiff
- type Config
- type Constraint
- type Enum
- type Error
- func NewConfigError(op string, err error) *Error
- func NewConnectionError(op string, err error) *Error
- func NewError(errType ErrorType, op string, err error) *Error
- func NewGenerationError(op string, err error) *Error
- func NewMigrationError(op string, err error) *Error
- func NewORMError(op string, err error) *Error
- func NewSchemaError(op string, err error) *Error
- func NewValidationError(op string, err error) *Error
- type ErrorType
- type ForeignKey
- type Function
- type GenerateOptions
- type Index
- type Logger
- type MigrateOptions
- type Migration
- type MigrationRecord
- type MigrationStatus
- type Migrator
- type ORM
- type ORMGenerator
- type Option
- func WithAutoMigrate(enabled bool) Option
- func WithAutoMigrateOptions(opts AutoMigrateOptions) Option
- func WithConfig(other *Config) Option
- func WithConfigFile(path string) Option
- func WithConnMaxLifetime(d time.Duration) Option
- func WithDebug(enabled bool) Option
- func WithDriver(driver string) Option
- func WithGenerateHooks(enabled bool) Option
- func WithGenerateMocks(enabled bool) Option
- func WithGenerateTests(enabled bool) Option
- func WithLogger(logger Logger) Option
- func WithMaxConnections(max int) Option
- func WithMaxIdleConnections(max int) Option
- func WithMigrationsDir(dir string) Option
- func WithMigrationsTable(table string) Option
- func WithModelsPackage(path string) Option
- func WithNamingConvention(convention string) Option
- func WithStrictMode(enabled bool) Option
- type PrimaryKey
- type Schema
- type SchemaDiff
- type SchemaInspector
- type Storm
- func (s *Storm) AutoMigrate(ctx context.Context, opts ...AutoMigrateOptions) error
- func (s *Storm) Close() error
- func (s *Storm) Config() *Config
- func (s *Storm) DB() *sqlx.DB
- func (s *Storm) Generate(ctx context.Context, opts ...GenerateOptions) error
- func (s *Storm) Introspect(ctx context.Context) (*Schema, error)
- func (s *Storm) Logger() Logger
- func (s *Storm) Migrate(ctx context.Context, opts ...MigrateOptions) error
- func (s *Storm) Migrator() Migrator
- func (s *Storm) ORM() *ORM
- func (s *Storm) Ping(ctx context.Context) error
- func (s *Storm) Schema() SchemaInspector
- func (s *Storm) Status(ctx context.Context) (*MigrationStatus, error)
- type Table
- type TableDiff
- type View
Constants ¶
const ( Version = "1.0.0-alpha" APIVersion = "v1" MinGoVersion = "1.24" )
Version information
Variables ¶
var ( ErrClosed = errors.New("storm: connection closed") ErrNoConnection = errors.New("storm: no database connection") ErrInvalidConfig = errors.New("storm: invalid configuration") ErrMigrationFailed = errors.New("storm: migration failed") ErrSchemaInvalid = errors.New("storm: invalid schema") ErrNotImplemented = errors.New("storm: not implemented") ErrMigrationExists = errors.New("storm: migration already exists") ErrMigrationNotFound = errors.New("storm: migration not found") ErrDestructiveChange = errors.New("storm: destructive change detected") )
Common errors
var ( MigratorFactory func(db *sqlx.DB, config *Config, logger Logger) Migrator ORMFactory func(config *Config, logger Logger) ORMGenerator SchemaInspectorFactory func(db *sqlx.DB, config *Config, logger Logger) SchemaInspector )
Factory functions for implementations
var BuildInfo = struct { Version string APIVersion string GitCommit string BuildDate string GoVersion string }{ Version: Version, APIVersion: APIVersion, GoVersion: runtime.Version(), }
BuildInfo contains build information
Functions ¶
func FullVersionInfo ¶
func FullVersionInfo() string
FullVersionInfo returns detailed version information
func IsVersionCompatible ¶
IsVersionCompatible checks if the current version is compatible with the minimum required version
func SetBuildInfo ¶
func SetBuildInfo(commit, date, goVersion string)
SetBuildInfo is called by the build process
Types ¶
type AutoMigrateOptions ¶ added in v0.0.49
type AutoMigrateOptions struct {
AllowDestructive bool
DryRun bool
CreateDBIfNotExists bool
LockTimeout time.Duration
}
AutoMigrateOptions configures automatic schema migration
type Column ¶
type Column struct {
Name string
Type string
Nullable bool
Default string
Length int
Precision int
Scale int
IsPrimaryKey bool
IsForeignKey bool
}
Column represents a table column
type ColumnDiff ¶
type ColumnDiff struct {
TypeChanged bool
OldType string
NewType string
NullableChanged bool
OldNullable bool
NewNullable bool
DefaultChanged bool
OldDefault string
NewDefault string
}
ColumnDiff represents differences between column schemas
func (*ColumnDiff) IsEmpty ¶
func (cd *ColumnDiff) IsEmpty() bool
IsEmpty returns true if the column diff has no changes
type Config ¶
type Config struct {
// Database settings
Driver string `yaml:"driver" env:"STORM_DRIVER"`
DatabaseURL string `yaml:"database_url" env:"STORM_DATABASE_URL"`
MaxOpenConns int `yaml:"max_open_conns" env:"STORM_MAX_OPEN_CONNS"`
MaxIdleConns int `yaml:"max_idle_conns" env:"STORM_MAX_IDLE_CONNS"`
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" env:"STORM_CONN_MAX_LIFETIME"`
// Models settings
ModelsPackage string `yaml:"models_package" env:"STORM_MODELS_PACKAGE"`
// Migration settings
MigrationsDir string `yaml:"migrations_dir" env:"STORM_MIGRATIONS_DIR"`
MigrationsTable string `yaml:"migrations_table" env:"STORM_MIGRATIONS_TABLE"`
AutoMigrate bool `yaml:"auto_migrate" env:"STORM_AUTO_MIGRATE"`
AutoMigrateOpts AutoMigrateOptions `yaml:"-"`
// ORM settings
GenerateHooks bool `yaml:"generate_hooks" env:"STORM_GENERATE_HOOKS"`
GenerateTests bool `yaml:"generate_tests" env:"STORM_GENERATE_TESTS"`
GenerateMocks bool `yaml:"generate_mocks" env:"STORM_GENERATE_MOCKS"`
// Schema settings
StrictMode bool `yaml:"strict_mode" env:"STORM_STRICT_MODE"`
NamingConvention string `yaml:"naming_convention" env:"STORM_NAMING_CONVENTION"`
// Runtime settings
Logger Logger `yaml:"-"`
Debug bool `yaml:"debug" env:"STORM_DEBUG"`
}
Config holds all Storm configuration
func LoadConfig ¶
LoadConfig loads configuration from file and environment
func (*Config) LoadEnv ¶
func (c *Config) LoadEnv()
LoadEnv loads configuration from environment variables
type Constraint ¶
Constraint represents a database constraint
type Error ¶
Error represents a Storm error with context
func NewConfigError ¶
NewConfigError creates a configuration error
func NewConnectionError ¶
NewConnectionError creates a connection error
func NewGenerationError ¶
NewGenerationError creates a generation error
func NewMigrationError ¶
NewMigrationError creates a migration error
func NewSchemaError ¶
NewSchemaError creates a schema error
func NewValidationError ¶
NewValidationError creates a validation error
func (*Error) WithDetails ¶
WithDetails adds details to the error
type ErrorType ¶
type ErrorType string
ErrorType represents the type of error
const ( ErrorTypeConnection ErrorType = "connection" ErrorTypeConfig ErrorType = "config" ErrorTypeMigration ErrorType = "migration" ErrorTypeSchema ErrorType = "schema" ErrorTypeORM ErrorType = "orm" ErrorTypeGeneration ErrorType = "generation" ErrorTypeValidation ErrorType = "validation" ErrorTypeUnknown ErrorType = "unknown" )
type ForeignKey ¶
ForeignKey represents a foreign key constraint
type GenerateOptions ¶
type GenerateOptions struct {
PackagePath string
OutputDir string
IncludeHooks bool
IncludeTests bool
IncludeMocks bool
}
GenerateOptions configures ORM code generation
type Logger ¶
type Logger interface {
Debug(msg string, fields ...interface{})
Info(msg string, fields ...interface{})
Warn(msg string, fields ...interface{})
Error(msg string, fields ...interface{})
}
Logger defines logging interface
func NewDefaultLogger ¶
func NewDefaultLogger() Logger
DefaultLogger creates a simple default logger
type MigrateOptions ¶
type MigrateOptions struct {
Name string
PackagePath string
OutputDir string
DryRun bool
AllowDestructive bool
SkipPrompt bool
CreateDBIfNotExists bool
}
MigrateOptions configures migration generation
type Migration ¶
type Migration struct {
ID string
Name string
Version string
Description string
UpSQL string
DownSQL string
Checksum string
CreatedAt time.Time
}
Migration represents a database migration
type MigrationRecord ¶
type MigrationRecord struct {
ID string
Version string
AppliedAt time.Time
AppliedBy string
Duration time.Duration
Success bool
Error string
}
MigrationRecord represents an applied migration
type MigrationStatus ¶
MigrationStatus represents current migration state
type Migrator ¶
type Migrator interface {
// Generate creates a new migration by comparing models with database
Generate(ctx context.Context, opts MigrateOptions) (*Migration, error)
// Apply executes a migration
Apply(ctx context.Context, migration *Migration) error
// Rollback reverses a migration
Rollback(ctx context.Context, migration *Migration) error
// Status returns the current migration status
Status(ctx context.Context) (*MigrationStatus, error)
// History returns all applied migrations
History(ctx context.Context) ([]*MigrationRecord, error)
// Pending returns all pending migrations
Pending(ctx context.Context) ([]*Migration, error)
// AutoMigrate reads Go structs and applies schema changes directly to the database
AutoMigrate(ctx context.Context, opts AutoMigrateOptions) error
}
Migrator handles database migrations
type ORMGenerator ¶
type ORMGenerator interface {
Generate(ctx context.Context, opts GenerateOptions) error
}
type Option ¶
Option configures Storm
func WithAutoMigrate ¶
WithAutoMigrate enables automatic migrations
func WithAutoMigrateOptions ¶ added in v0.0.49
func WithAutoMigrateOptions(opts AutoMigrateOptions) Option
WithAutoMigrateOptions configures automatic migration behavior
func WithConfigFile ¶
WithConfigFile loads configuration from file
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets connection lifetime
func WithGenerateHooks ¶
WithGenerateHooks enables hook generation
func WithGenerateMocks ¶
WithGenerateMocks enables mock generation
func WithGenerateTests ¶
WithGenerateTests enables test generation
func WithMaxConnections ¶
WithMaxConnections sets connection pool size
func WithMaxIdleConnections ¶
WithMaxIdleConnections sets max idle connections
func WithMigrationsDir ¶
WithMigrationsDir sets the migrations directory
func WithMigrationsTable ¶
WithMigrationsTable sets the migrations table name
func WithModelsPackage ¶
WithModelsPackage sets the models package path
func WithNamingConvention ¶
WithNamingConvention sets the naming convention
type PrimaryKey ¶
PrimaryKey represents a primary key constraint
type Schema ¶
type Schema struct {
Tables map[string]*Table
Views []*View
Functions []*Function
Indexes []*Index
Constraints []*Constraint
Enums []*Enum
}
Schema represents a database schema
type SchemaDiff ¶
type SchemaDiff struct {
AddedTables map[string]*Table
DroppedTables map[string]*Table
ModifiedTables map[string]*TableDiff
}
SchemaDiff represents differences between schemas
type SchemaInspector ¶
type SchemaInspector interface {
// Inspect returns the current database schema
Inspect(ctx context.Context) (*Schema, error)
// Compare compares two schemas
Compare(ctx context.Context, from, to *Schema) (*SchemaDiff, error)
// ExportSQL exports schema as SQL
ExportSQL(ctx context.Context) (string, error)
// ExportGo exports schema as Go structs
ExportGo(ctx context.Context) (string, error)
}
SchemaInspector analyzes database schema
type Storm ¶
type Storm struct {
// contains filtered or unexported fields
}
Storm is the main entry point for all database operations
func NewWithConfig ¶
NewWithConfig creates a new Storm instance with explicit configuration
func (*Storm) AutoMigrate ¶ added in v0.0.49
func (s *Storm) AutoMigrate(ctx context.Context, opts ...AutoMigrateOptions) error
AutoMigrate reads Go structs and applies schema changes directly to the database
func (*Storm) Generate ¶
func (s *Storm) Generate(ctx context.Context, opts ...GenerateOptions) error
Generate creates ORM code from models
func (*Storm) Introspect ¶
Introspect analyzes the database schema
func (*Storm) Migrate ¶
func (s *Storm) Migrate(ctx context.Context, opts ...MigrateOptions) error
Migrate generates and optionally applies migrations
type Table ¶
type Table struct {
Name string
Schema string
Columns map[string]*Column
PrimaryKey *PrimaryKey
ForeignKeys []*ForeignKey
Indexes []*Index
Constraints []*Constraint
}
Table represents a database table