Documentation
¶
Overview ¶
Package postgres provides PostgreSQL connection builders for different drivers.
Index ¶
- type Builder
- type GORMBuilder
- func (b *GORMBuilder) Connect() (*gorm.DB, error)
- func (b *GORMBuilder) WithConnMaxLifetime(d time.Duration) *GORMBuilder
- func (b *GORMBuilder) WithDSN(dsn string) *GORMBuilder
- func (b *GORMBuilder) WithMaxIdleConns(n int) *GORMBuilder
- func (b *GORMBuilder) WithMaxOpenConns(n int) *GORMBuilder
- func (b *GORMBuilder) WithPrepareStmt(enabled bool) *GORMBuilder
- type PGXBuilder
- func (b *PGXBuilder) Connect(ctx context.Context) (*pgxpool.Pool, error)
- func (b *PGXBuilder) WithDSN(dsn string) *PGXBuilder
- func (b *PGXBuilder) WithMaxConnIdleTime(d time.Duration) *PGXBuilder
- func (b *PGXBuilder) WithMaxConnLifetime(d time.Duration) *PGXBuilder
- func (b *PGXBuilder) WithMaxConns(n int32) *PGXBuilder
- func (b *PGXBuilder) WithMinConns(n int32) *PGXBuilder
- type SQLBuilder
- func (b *SQLBuilder) Connect() (*sql.DB, error)
- func (b *SQLBuilder) WithConnMaxIdleTime(d time.Duration) *SQLBuilder
- func (b *SQLBuilder) WithConnMaxLifetime(d time.Duration) *SQLBuilder
- func (b *SQLBuilder) WithDSN(dsn string) *SQLBuilder
- func (b *SQLBuilder) WithMaxIdleConns(n int) *SQLBuilder
- func (b *SQLBuilder) WithMaxOpenConns(n int) *SQLBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct{}
Builder is the entry point for PostgreSQL connections.
func (Builder) GORM ¶
func (Builder) GORM() *GORMBuilder
GORM returns a GORM-based PostgreSQL builder.
func (Builder) SQL ¶
func (Builder) SQL() *SQLBuilder
SQL returns a database/sql based PostgreSQL builder.
type GORMBuilder ¶
type GORMBuilder struct {
// contains filtered or unexported fields
}
GORMBuilder builds a GORM PostgreSQL connection.
func NewGORMBuilder ¶
func NewGORMBuilder() *GORMBuilder
NewGORMBuilder creates a new GORM builder with sensible defaults.
func (*GORMBuilder) Connect ¶
func (b *GORMBuilder) Connect() (*gorm.DB, error)
Connect establishes a connection to PostgreSQL using GORM.
func (*GORMBuilder) WithConnMaxLifetime ¶
func (b *GORMBuilder) WithConnMaxLifetime(d time.Duration) *GORMBuilder
WithConnMaxLifetime sets the maximum connection lifetime. Default: 10 minutes
func (*GORMBuilder) WithDSN ¶
func (b *GORMBuilder) WithDSN(dsn string) *GORMBuilder
WithDSN sets the database connection string. Required.
func (*GORMBuilder) WithMaxIdleConns ¶
func (b *GORMBuilder) WithMaxIdleConns(n int) *GORMBuilder
WithMaxIdleConns sets the maximum number of idle connections. Default: 10
func (*GORMBuilder) WithMaxOpenConns ¶
func (b *GORMBuilder) WithMaxOpenConns(n int) *GORMBuilder
WithMaxOpenConns sets the maximum number of open connections. Default: 100
func (*GORMBuilder) WithPrepareStmt ¶
func (b *GORMBuilder) WithPrepareStmt(enabled bool) *GORMBuilder
WithPrepareStmt enables prepared statement mode. Default: false
type PGXBuilder ¶
type PGXBuilder struct {
// contains filtered or unexported fields
}
PGXBuilder builds a pgx PostgreSQL connection pool.
func NewPGXBuilder ¶
func NewPGXBuilder() *PGXBuilder
NewPGXBuilder creates a new PGX builder with sensible defaults.
func (*PGXBuilder) WithDSN ¶
func (b *PGXBuilder) WithDSN(dsn string) *PGXBuilder
WithDSN sets the database connection string. Required.
func (*PGXBuilder) WithMaxConnIdleTime ¶
func (b *PGXBuilder) WithMaxConnIdleTime(d time.Duration) *PGXBuilder
WithMaxConnIdleTime sets the maximum connection idle time. Default: 5 minutes
func (*PGXBuilder) WithMaxConnLifetime ¶
func (b *PGXBuilder) WithMaxConnLifetime(d time.Duration) *PGXBuilder
WithMaxConnLifetime sets the maximum connection lifetime. Default: 10 minutes
func (*PGXBuilder) WithMaxConns ¶
func (b *PGXBuilder) WithMaxConns(n int32) *PGXBuilder
WithMaxConns sets the maximum number of connections. Default: 100
func (*PGXBuilder) WithMinConns ¶
func (b *PGXBuilder) WithMinConns(n int32) *PGXBuilder
WithMinConns sets the minimum number of connections. Default: 10
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
SQLBuilder builds a database/sql PostgreSQL connection.
func NewSQLBuilder ¶
func NewSQLBuilder() *SQLBuilder
NewSQLBuilder creates a new SQL builder with sensible defaults.
func (*SQLBuilder) Connect ¶
func (b *SQLBuilder) Connect() (*sql.DB, error)
Connect establishes a connection to PostgreSQL using database/sql.
func (*SQLBuilder) WithConnMaxIdleTime ¶
func (b *SQLBuilder) WithConnMaxIdleTime(d time.Duration) *SQLBuilder
WithConnMaxIdleTime sets the maximum connection idle time. Default: 5 minutes
func (*SQLBuilder) WithConnMaxLifetime ¶
func (b *SQLBuilder) WithConnMaxLifetime(d time.Duration) *SQLBuilder
WithConnMaxLifetime sets the maximum connection lifetime. Default: 10 minutes
func (*SQLBuilder) WithDSN ¶
func (b *SQLBuilder) WithDSN(dsn string) *SQLBuilder
WithDSN sets the database connection string. Required.
func (*SQLBuilder) WithMaxIdleConns ¶
func (b *SQLBuilder) WithMaxIdleConns(n int) *SQLBuilder
WithMaxIdleConns sets the maximum number of idle connections. Default: 10
func (*SQLBuilder) WithMaxOpenConns ¶
func (b *SQLBuilder) WithMaxOpenConns(n int) *SQLBuilder
WithMaxOpenConns sets the maximum number of open connections. Default: 100