Documentation
¶
Index ¶
Constants ¶
View Source
const ( MigrationsTableName = "liquor_migrations" MigrationsLocksTableName = "liquor_migrations_locks" )
Variables ¶
View Source
var Module = fx.Module("liquor-adapter-database", fx.Provide( NewConnection, NewProvider, ))
Functions ¶
Types ¶
type ConnectionOutput ¶ added in v2.5.0
func NewConnection ¶
func NewConnection(cfg *config.Config, logger *zap.Logger) ConnectionOutput
NewConnection creates a new database connection using the Bun ORM. It supports multiple database drivers (SQLite, MySQL, PostgreSQL) based on configuration.
Parameters:
- cfg: configuration object containing database settings
- logger: zap logger instance for error reporting
Returns:
- *bun.DB: configured database connection instance
The function will fatal log if connection fails. Supported drivers:
- SQLite
- MySQL
- PostgreSQL
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
func NewProvider ¶
func (*Provider) CreateIndexIfNotExists ¶
CreateIndexIfNotExists creates a new database index for the given model if it doesn't already exist. It uses the Bun ORM's schema creation capabilities to generate the index.
Parameters:
- n: any struct that represents a database model
- name: the name of the index to be created
- colums: variadic list of column names to be included in the index
Returns:
- error: returns nil if successful, otherwise returns the error that occurred
Example:
type User struct {
ID int64 `bun:"id,pk,autoincrement"`
Email string `bun:"email,notnull"`
}
err := provider.CreateIndexIfNotExists(&User{}, "idx_user_email", "email")
func (*Provider) CreateTableIfNotExists ¶
CreateTableIfNotExists creates a new database table for the given model if it doesn't already exist. It uses the Bun ORM's schema creation capabilities to generate the table structure.
Parameters:
- n: any struct that represents a database model
Returns:
- error: returns nil if successful, otherwise returns the error that occurred
Example:
type User struct {
ID int64 `bun:"id,pk,autoincrement"`
Name string `bun:"name,notnull"`
}
err := provider.CreateTableIfNotExists(&User{})
Click to show internal directories.
Click to hide internal directories.