gorm

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMaxIdleConnections = 10
	DefaultMaxOpenConnections = 100
)

Functions

func New

func New(tables []interface{}, opts ...Option) (*gorm.DB, error)

New returns a new gorm.DB instance with options.

The default options are:

  • MaxIdleConnections: DefaultMaxIdleConnections
  • MaxOpenConnections: DefaultMaxOpenConnections
  • EnableAutoMigrate: true

Types

type Option added in v0.6.0

type Option func(*Options)

func WithEnableAutoMigrate added in v0.6.0

func WithEnableAutoMigrate(enableAutoMigrate bool) Option

WithEnableAutoMigrate sets the flag to enable auto migrate.

func WithMaxIdleConns added in v0.6.0

func WithMaxIdleConns(maxIdleConns int) Option

WithMaxIdleConns sets the maximum number of connections in the idle connection pool.

func WithMaxOpenConns added in v0.6.0

func WithMaxOpenConns(maxOpenConns int) Option

WithMaxOpenConns sets the maximum number of open connections to the database.

func WithSource added in v0.6.0

func WithSource(source string) Option

WithSource sets the database connection string.

type Options

type Options struct {
	// Source is the database connection string.
	Source string

	// MaxIdleConns is the maximum number of connections in the idle connection pool.
	MaxIdleConnections int

	// MaxOpenConns is the maximum number of open connections to the database.
	MaxOpenConnections int

	// EnableAutoMigrate is the flag to enable auto migrate.
	EnableAutoMigrate bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL