pool

package
v1.70.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	DSN      string
	ReadOnly bool
}

Connection represents a single database connection configuration.

type Option

type Option func(*Options)

Option configures database connection settings.

func WithConnection

func WithConnection(dsn string, readOnly bool) Option

WithConnection returns an Option to configure the database connection dsn. Multiple calls with the same DSN but different readOnly flags are supported.

func WithConnections

func WithConnections(connections []Connection) Option

WithConnections returns an Option to configure database connections from a slice. Supports adding multiple connections including the same DSN with different readOnly flags.

func WithInsertBatchSize added in v1.63.3

func WithInsertBatchSize(insertBatchSize int) Option

WithInsertBatchSize returns an Option to configure the database connection insert batch size.

func WithMaxIdle

func WithMaxIdle(maxIdle int) Option

WithMaxIdle returns an Option to configure the database connection max idle connections.

func WithMaxLifetime

func WithMaxLifetime(maxLifetime time.Duration) Option

WithMaxLifetime returns an Option to configure the database connection max lifetime.

func WithMaxOpen

func WithMaxOpen(maxOpen int) Option

WithMaxOpen returns an Option to configure the database connection max open connections.

func WithPreferSimpleProtocol

func WithPreferSimpleProtocol(preferSimpleProtocol bool) Option

WithPreferSimpleProtocol returns an Option to configure the database connection prefer simple protocol.

func WithPreparedStatements added in v1.64.2

func WithPreparedStatements(enabled bool) Option

WithPreparedStatements returns an Option to enable or disable the prepared statement cache.

func WithSkipDefaultTransaction

func WithSkipDefaultTransaction(skipDefaultTransaction bool) Option

WithSkipDefaultTransaction returns an Option to configure the database connection skip default transaction.

func WithTraceConfig

func WithTraceConfig(traceConfig config.ConfigurationDatabaseTracing) Option

WithTraceConfig returns an Option to configure the database connection trace config.

type Options

type Options struct {
	Connections []Connection

	MaxOpen     int
	MaxIdle     int
	MaxLifetime time.Duration

	PreferSimpleProtocol   bool
	SkipDefaultTransaction bool

	TraceConfig     config.ConfigurationDatabaseTracing
	InsertBatchSize int

	PreparedStatements bool
}

Options holds Datastore connection configuration.

type Pool

type Pool interface {
	DB(ctx context.Context, readOnly bool) *gorm.DB

	AddConnection(ctx context.Context, opts ...Option) error

	CanMigrate() bool
	SaveMigration(ctx context.Context, migrationPatches ...*migration.Patch) error
	// Migrate finds missing migrations and records them in the database.
	Migrate(ctx context.Context, migrationsDirPath string, migrations ...any) error

	Close(ctx context.Context)
}

func NewPool

func NewPool(_ context.Context) Pool

Jump to

Keyboard shortcuts

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