postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg Config) *Client

func NewClientFromEnv

func NewClientFromEnv() *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)

func (*Client) ExecBatch

func (c *Client) ExecBatch(ctx context.Context, queries []string, args [][]any) error

func (*Client) ExecTx

func (c *Client) ExecTx(ctx context.Context, fn func(pgx.Tx) error) error

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) Pool

func (c *Client) Pool() *pgxpool.Pool

func (*Client) QueryRow

func (c *Client) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

func (*Client) QueryRows

func (c *Client) QueryRows(ctx context.Context, query string, args ...any) (pgx.Rows, error)

type Config

type Config struct {
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
	SSLMode  string
	Timeout  time.Duration
	MaxConns int32
	Logger   *logger.Logger
}

type Migration

type Migration struct {
	Version     int
	Description string
	SQL         string
	Timestamp   time.Time
}

func LoadMigrationsFromPath

func LoadMigrationsFromPath(migrationsPath string) ([]Migration, error)

LoadMigrationsFromPath loads migrations from SQL files in the specified directory path. The function expects SQL files to be named with the pattern: {version}_{description}.sql where version is a numeric identifier and description is the migration description. example: 001_create_users.sql

type MigrationManager

type MigrationManager struct {
	// contains filtered or unexported fields
}

func NewMigrationManager

func NewMigrationManager(client *Client) *MigrationManager

func (*MigrationManager) ApplyMigration

func (m *MigrationManager) ApplyMigration(ctx context.Context, migration Migration) error

func (*MigrationManager) GetAppliedMigrations

func (m *MigrationManager) GetAppliedMigrations(ctx context.Context) (map[int]time.Time, error)

func (*MigrationManager) InitMigrationTable

func (m *MigrationManager) InitMigrationTable(ctx context.Context) error

func (*MigrationManager) Migrate

func (m *MigrationManager) Migrate(ctx context.Context, migrations []Migration) error

func (*MigrationManager) RollbackLastMigration

func (m *MigrationManager) RollbackLastMigration(ctx context.Context, rollbacks map[int]string) error

Jump to

Keyboard shortcuts

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