postgres

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL connection builders for different drivers.

Index

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 NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new PostgreSQL builder.

func (Builder) GORM

func (Builder) GORM() *GORMBuilder

GORM returns a GORM-based PostgreSQL builder.

func (Builder) PGX

func (Builder) PGX() *PGXBuilder

PGX returns a pgx-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) Connect

func (b *PGXBuilder) Connect(ctx context.Context) (*pgxpool.Pool, error)

Connect establishes a connection pool to PostgreSQL using pgx.

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

Jump to

Keyboard shortcuts

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