Documentation
¶
Index ¶
- Constants
- Variables
- func Transaction(ctx context.Context, handlers ...TransactionHandler) (err error)
- func TransactionWithSession(ctx context.Context, session *Session, handlers ...TransactionHandler) (err error)
- type Configuration
- type Database
- type EngineGroup
- type GonicMapper
- type Mapper
- type PrefixMapper
- type SameMapper
- type Service
- type Session
- type SnakeMapper
- type SuffixMapper
- type TransactionHandler
Constants ¶
View Source
const ( DefaultKey = "db" DefaultDriver = "mysql" DefaultDns = "root:pass@tcp(127.0.0.1)/test" DefaultMapper = "snake" DefaultMaxIdle = 2 DefaultMaxOpen = 30 DefaultMaxLifetime = 60 )
Variables ¶
View Source
var ( DefaultEnableSession = false DefaultEnableLogger = true )
Functions ¶
func Transaction ¶
func Transaction(ctx context.Context, handlers ...TransactionHandler) (err error)
func TransactionWithSession ¶
func TransactionWithSession(ctx context.Context, session *Session, handlers ...TransactionHandler) (err error)
Types ¶
type Configuration ¶
type Configuration interface { // Add // adds a database mapping to configuration. Add(key string, database *Database) (err error) // Del // deletes database from mapping and activated engine group. Del(key string) // Get // returns a shared database configuration. Get(keys ...string) (database *Database, exists bool) // GetEngine // returns a shared xorm engine group, creates a new when called // at first time. GetEngine(keys ...string) (*EngineGroup, error) // GetMaster // returns a shared xorm master session of a connection. GetMaster(ctx context.Context, keys ...string) (session *Session, err error) // GetSlave // returns a shared xorm slave session of a connection. GetSlave(ctx context.Context, keys ...string) (session *Session, err error) }
Configuration is an interface for connections.
var Config Configuration
Config is a singleton instance that constructed when package init.
type Database ¶
type Database struct { // Driver // database type. Accept mysql, mssql etc. // // Default: mysql Driver string `yaml:"driver"` // Dsn // is a list for database connection. First for them as primary and // others as slaves. Dsn []string `yaml:"dsn"` // Mapper // define. Mapper string `yaml:"mapper"` // MaxIdle // maximum number of idle connections maintained. The manager will close // unnecessary idle connections if there are too many idle connections. // // Default: 2 MaxIdle int `yaml:"max-idle"` // MaxOpen // maximum number of connections established. The manager will block and // wait for an idle connection to use. // // Default: 30 MaxOpen int `yaml:"max-open"` // MaxLifetime // a connection lifecycle. // // Default: 60 // Unit: second MaxLifetime int `yaml:"max-lifetime"` // EnableLogger // is a flag for enable logger. The manager will send sql to logging // system if enabled. EnableLogger *bool `yaml:"enable-logger"` // EnableSession // is a flag for enable session. The manager will create a session // id for each connection. EnableSession *bool `yaml:"enable-session"` // contains filtered or unexported fields }
Database is a component for db connection configurations.
type EngineGroup ¶
type EngineGroup = xorm.EngineGroup
type GonicMapper ¶
type GonicMapper = names.GonicMapper
type PrefixMapper ¶
type PrefixMapper = names.PrefixMapper
type SameMapper ¶
type SameMapper = names.SameMapper
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is a top level component used to operate database.
type SnakeMapper ¶
type SnakeMapper = names.SnakeMapper
type SuffixMapper ¶
type SuffixMapper = names.SuffixMapper
Click to show internal directories.
Click to hide internal directories.