Documentation
¶
Index ¶
- Constants
- func CreateDatabaseIfNotExists(driverName, dataSourceName, databaseName string, ops ...Option) error
- func GormComment(description string) string
- func NewConnection(config *Config, ops ...Option) (*gorm.DB, error)
- func NewDataSourceName(host, username, password, database string, ops ...Option) string
- func NewDataSourceNameForConfig(config *Config, ops ...Option) string
- func NewDataSourceNameForNoSelectDatabase(host, username, password string, ops ...Option) string
- type Config
- type DriverName
- type Option
- func WithCharset(charset string) Option
- func WithDisableForeignKeyConstraintWhenMigrating(disable bool) Option
- func WithDriverName(driverName DriverName) Option
- func WithLocation(loc string) Option
- func WithLogLevel(logLevel int) Option
- func WithLogger(logger logger.Interface) Option
- func WithNamingStrategy(strategy schema.NamingStrategy) Option
- func WithParseTime(parseTime bool) Option
Constants ¶
View Source
const (
DefaultCreateBatchSize = 1000
)
Variables ¶
This section is empty.
Functions ¶
func CreateDatabaseIfNotExists ¶
func CreateDatabaseIfNotExists(driverName, dataSourceName, databaseName string, ops ...Option) error
CreateDatabaseIfNotExists If database not exists, then create it.
func GormComment ¶
GormComment get table comment for the description.
func NewConnection ¶
NewConnection create a new gorm db instance with the given options.
func NewDataSourceName ¶
NewDataSourceName initialize database of the data source name. If database parameter is empty, will not choose database, such as only open database connection.
func NewDataSourceNameForConfig ¶
NewDataSourceNameForConfig Get data source name for given options.
Types ¶
type Config ¶
type Config struct { Host string Username string Password string Database string MaxIdleConnections int MaxOpenConnections int MaxConnectionLifeTime time.Duration }
Config defines config for database.
type DriverName ¶
type DriverName string
const ( DriverNameOfMySQL DriverName = "mysql" DriverNameOfSQLite DriverName = "sqlite" )
func (DriverName) String ¶
func (d DriverName) String() string
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithCharset ¶
func WithDisableForeignKeyConstraintWhenMigrating ¶ added in v0.1.3
func WithDriverName ¶ added in v0.1.4
func WithDriverName(driverName DriverName) Option
func WithLocation ¶
func WithLogLevel ¶ added in v0.1.3
func WithLogger ¶ added in v0.1.3
func WithNamingStrategy ¶ added in v0.1.3
func WithNamingStrategy(strategy schema.NamingStrategy) Option
func WithParseTime ¶
Click to show internal directories.
Click to hide internal directories.