Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config = struct {
DBConnection string
DBHost string
DBUsername string
DBPassword string
DBDatabase string
DBPort string
SSLMode string
SimpleProtocol bool
// If MaxOpenConnections is 0, there is no limit on the number of opened connections
MaxOpenConnections int
// MaxIdleConnections cannot be greater than MaxOpenConnections. In that case, it will be reduced to match MaxOpenConnections
MaxIdleConnections int
// ExtraOptions allows one to provide more options based on the functional
// option pattern.
//
// Those options are the same as those provided to New. See [Option] for
// more details.
//
// Note that a functional provided directly via New has higher priority than
// the same option provided here.
ExtraOptions []Option
}
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func New ¶
func New(name string, c *Config, opts ...Option) *Connection
New creates a new database connection based on the specified configuration / options.
c is the mandatory database configuration. It must not be nil.
See With* prefixed Option helpers for further customization. Those can be provided via variadic opts or alternatively via connection.Config.ExtraOptions.
func (*Connection) DB ¶
func (c *Connection) DB() *gorm.DB
func (*Connection) DoTransaction ¶
func (c *Connection) DoTransaction() (apply func(), rollback func())
func (*Connection) Name ¶
func (c *Connection) Name() string
type Option ¶ added in v1.6.0
type Option = func(c *configExt)
Option is the return type for this module's With* prefixed option helpers.
Those can be provided to New in order to customize its behavior. Alternatively, they can also be provided via connection.Config.ExtraOptions.
func WithSlowSqlThreshold ¶ added in v1.6.0
WithSlowSqlThreshold customizes a query's elapsed duration after which the system will start to emit "slow sql" log entries.
Use 0 to disable this feature.
It defaults to 500ms when unspecified.