Documentation
¶
Index ¶
- type Attribute
- type AttributeMigrate
- type Config
- type Connection
- type DatabaseConfig
- func (c *DatabaseConfig) AddSchema(s string)
- func (c *DatabaseConfig) ErrorHandler(ctx context.Context, err error) error
- func (c *DatabaseConfig) ErrorQueryHandler(ctx context.Context, query Query) error
- func (c *DatabaseConfig) InfoHandler(ctx context.Context, query Query)
- func (c *DatabaseConfig) Init(driverName string, errorTranslator func(err error) error)
- func (c *DatabaseConfig) InitCallback() func() error
- func (c *DatabaseConfig) Schemas() []string
- func (c *DatabaseConfig) SetInitCallback(f func() error)
- func (c *DatabaseConfig) SetSchemas(s []string)
- type Driver
- type IndexMigrate
- type JoinType
- type Logger
- type ManyToSomeMigrate
- type Migrator
- type OneToSomeMigrate
- type PrimaryKeyMigrate
- type Query
- type QueryType
- type Row
- type Rows
- type SavePoint
- type Table
- type TableMigrate
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttributeMigrate ¶
type AttributeMigrate struct {
Nullable bool
FieldName string
Name string
EscapingName string
DataType string
Default string
}
AttributeMigrate represents a column to be created during migration.
type Config ¶
type Config interface {
Name() string
GetDatabaseConfig() *DatabaseConfig
}
Config represents a database configuration.
type Connection ¶
type Connection interface {
ExecContext(ctx context.Context, query *Query) error
QueryRowContext(ctx context.Context, query *Query) Row
QueryContext(ctx context.Context, query *Query) (Rows, error)
}
Connection represents a database connection.
type DatabaseConfig ¶
type DatabaseConfig struct {
Logger Logger
IncludeArguments bool // include all arguments used on query
QueryThreshold time.Duration // query threshold to warning on slow queries
// contains filtered or unexported fields
}
DatabaseConfig contains database configuration including logging and error handling settings.
func (*DatabaseConfig) AddSchema ¶
func (c *DatabaseConfig) AddSchema(s string)
AddSchema adds a schema to the list of schemas for the database.
func (*DatabaseConfig) ErrorHandler ¶
func (c *DatabaseConfig) ErrorHandler(ctx context.Context, err error) error
ErrorHandler logs the database error using the configured logger.
func (*DatabaseConfig) ErrorQueryHandler ¶
func (c *DatabaseConfig) ErrorQueryHandler(ctx context.Context, query Query) error
ErrorQueryHandler logs the query error using the configured logger.
func (*DatabaseConfig) InfoHandler ¶
func (c *DatabaseConfig) InfoHandler(ctx context.Context, query Query)
InfoHandler logs the query information using the configured logger.
func (*DatabaseConfig) Init ¶
func (c *DatabaseConfig) Init(driverName string, errorTranslator func(err error) error)
Init initializes the database configuration with the given driver name and error translator.
func (*DatabaseConfig) InitCallback ¶
func (c *DatabaseConfig) InitCallback() func() error
InitCallback returns the initialization callback function for the database.
func (*DatabaseConfig) Schemas ¶
func (c *DatabaseConfig) Schemas() []string
Schemas returns the list of schemas configured for the database.
func (*DatabaseConfig) SetInitCallback ¶
func (c *DatabaseConfig) SetInitCallback(f func() error)
SetInitCallback sets the initialization callback function for the database.
func (*DatabaseConfig) SetSchemas ¶
func (c *DatabaseConfig) SetSchemas(s []string)
SetSchemas sets the list of schemas for the database.
type Driver ¶
type Driver interface {
MigrateContext(context.Context, *Migrator) error // MigrateContext migrates the database schema.
DropTable(schema, table string) error // DropTable drops a table from the database schema.
DropColumn(schema, table, column string) error // DropColumn drops a column from a table in the database schema.
RenameColumn(schema, table, oldColumn, newName string) error // RenameColumn renames a column in a table in the database schema.
RenameTable(schema, table, newName string) error // RenameTable renames a table in the database schema.
AddLogger(Logger, error) error // AddLogger adds a logger to the database driver.
ErrorTranslator() func(err error) error // ErrorTranslator translates database errors.
KeywordHandler(string) string // KeywordHandler handles SQL keywords in the database driver.
FormatTableName(schema, table string) string // FormatTableName formats the table name in the database driver.
SupportsReturning() bool // SupportsReturning checks if the database driver supports RETURNING clause.
NewConnection() Connection // NewConnection creates a new database connection.
NewTransaction(ctx context.Context, opts *sql.TxOptions) (Transaction, error) // NewTransaction creates a new database transaction.
Init() error // Init initializes the database schema.
Close() error // Close closes the database driver.
Stats() sql.DBStats // Stats returns the database statistics.
Config // Config represents a database configuration.
}
Driver represents a database driver.
type IndexMigrate ¶
type IndexMigrate struct {
Name string
EscapingName string
Unique bool
Func string
Attributes []AttributeMigrate
}
IndexMigrate represents an index to be created during migration.
type Logger ¶
type Logger interface {
InfoContext(ctx context.Context, msg string, kv ...any)
WarnContext(ctx context.Context, msg string, kv ...any)
ErrorContext(ctx context.Context, msg string, kv ...any)
}
Logger represents a logger for database operations.
type ManyToSomeMigrate ¶
type ManyToSomeMigrate struct {
TargetTable string
TargetColumn string
EscapingTargetTable string
EscapingTargetColumn string
TargetSchema *string
AttributeMigrate
}
ManyToSomeMigrate represents a many-to-one or many-to-many relationship for migration.
func (ManyToSomeMigrate) EscapingTargetTableName ¶
func (m ManyToSomeMigrate) EscapingTargetTableName() string
EscapingTargetTableName returns the target table and the schema.
type Migrator ¶
type Migrator struct {
Tables map[string]*TableMigrate
Schemas []string
Error error
}
Migrator represents a database migrator with its tables and schemas.
type OneToSomeMigrate ¶
type OneToSomeMigrate struct {
IsOneToMany bool
TargetTable string
TargetColumn string
EscapingTargetTable string
EscapingTargetColumn string
TargetSchema *string
AttributeMigrate
}
OneToSomeMigrate represents a one-to-one or one-to-many relationship for migration.
func (OneToSomeMigrate) EscapingTargetTableName ¶
func (o OneToSomeMigrate) EscapingTargetTableName() string
EscapingTargetTableName returns the target table and the schema.
type PrimaryKeyMigrate ¶
type PrimaryKeyMigrate struct {
AutoIncrement bool
AttributeMigrate
}
PrimaryKeyMigrate represents a primary key column with auto-increment flag.
type Query ¶
Query represents a SQL query with its arguments and duration.
func CreateQuery ¶
CreateQuery creates a new Query with the given raw SQL and arguments.
type QueryType ¶
type QueryType uint
QueryType represents the type of a SQL query.
const ( SelectQuery QueryType // SELECT query SelectJoinQuery // SELECT query with JOIN clause InsertQuery // INSERT query InsertAllQuery // INSERT ALL query UpdateQuery // UPDATE query UpdateJoinQuery // UPDATE query with JOIN clause DeleteQuery // DELETE query RawQuery // Raw SQL query )
type TableMigrate ¶
type TableMigrate struct {
Name string
EscapingName string
Schema *string
Migrated bool
PrimaryKeys []PrimaryKeyMigrate
Indexes []IndexMigrate
Attributes []AttributeMigrate
ManyToSomes []ManyToSomeMigrate
OneToSomes []OneToSomeMigrate
}
TableMigrate represents a table to be migrated with its columns, indexes, and relationships.
func (TableMigrate) EscapingTableName ¶
func (t TableMigrate) EscapingTableName() string
EscapingTableName returns the table and the schema.
type Transaction ¶
type Transaction interface {
Connection
Commit() error
Rollback() error
SavePoint() (SavePoint, error)
}
Transaction represents a database transaction.