Documentation ¶
Index ¶
Constants ¶
View Source
const ( // ErrEmptyConfig throws when db.ConnectionURL not passed into NewConnection ErrEmptyConfig = Error("empty config") // ErrEmptyAdapter throws when passed empty adapter into NewConnection ErrEmptyAdapter = Error("empty adapter") // ErrUnknownAdapter throws when passed unknown adapter into NewConnection ErrUnknownAdapter = Error("unknown adapter") // ErrConfigNotFound throws when config key is empty or not set ErrConfigNotFound = Error("configuration for key not found") )
Variables ¶
View Source
var ( // MySQLModule default connection to mysql MySQLModule = module.Module{ {Constructor: newMySQLConnection}, } // PostgresModule default connection to postgres PostgresModule = module.Module{ {Constructor: newPostgresConnection}, } )
Functions ¶
func NewConnection ¶
func NewConnection(opts ...ConnectionOption) (con db.Database, err error)
NewConnection creates new database connection by adapter and config
if cfg contains debug, than enable logging and replace default logger by zap.Logger
Types ¶
type ConnectionOption ¶
type ConnectionOption func(opts *ConnectionOptions)
ConnectionOption will be passed into NewConnection
func Adapter ¶
func Adapter(adapter string) ConnectionOption
Adapter pass connection adapter into options
func Config ¶
func Config(cfg db.ConnectionURL) ConnectionOption
Config pass connection url into options
func Logger ¶
func Logger(log *zap.Logger) ConnectionOption
Logger pass connection logger into options
func PrepareConfig ¶
PrepareConfig prepare options for connection
type ConnectionOptions ¶
ConnectionOptions will be passed into NewConnection
type ConnectionResult ¶
type ConnectionResult struct { dig.Out MySQL MySQL `optional:"true" name:"default_mysql"` PG PG `optional:"true" name:"default_pg"` }
ConnectionResult for default module
type MySQL ¶
type MySQL interface { db.Database sqlbuilder.SQLBuilder }
MySQL is wrapper over upper/db Database
type PG ¶
type PG interface { db.Database sqlbuilder.SQLBuilder }
PG is wrapper over upper/db Database
Click to show internal directories.
Click to hide internal directories.