tinypostgres

package
v1.0.68 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tinypostgres provides utilities for handling Postgres.

Index

Constants

View Source
const (
	// ErrUnknown is returned for all errors with unknown cause.
	ErrUnknown = iota

	// ErrUniqueViolation is returned for unique constraint violations.
	ErrUniqueViolation

	// ErrNotNullViolation is returned for non-null constraint violations.
	ErrNotNullViolation

	// ErrRecordNotFound is returned when query is expected to return a single record, but none are returned.
	ErrRecordNotFound

	// ErrInvalidText is returned when you try assigned invalid value to types such as uuid.
	ErrInvalidText
)

Variables

This section is empty.

Functions

func Dial added in v1.0.15

func Dial(url string, config ...*Config) (*gorm.DB, error)

Dial creates a connection to Postgres, and returns *gorm.DB instance.

Types

type Config

type Config struct {
	// Verbose specifies whether to log all executed queries.
	Verbose bool

	// PoolMaxOpen is the maximum number of open connections to the database (default: 10).
	PoolMaxOpen int

	// PoolMaxIdle is the maximum number of connections in the idle connection pool (default: 5).
	PoolMaxIdle int

	// PoolMaxLifetime is the maximum amount of time a connection may be reused (default: 1h).
	PoolMaxLifetime time.Duration

	// PoolMaxIdleTime is the maximum amount of time a connection may be idle (default: 30m).
	PoolMaxIdleTime time.Duration

	// GormOpt allows to specify custom function that will operate directly on *gorm.Config.
	GormOpt func(*gorm.Config)
}

Config holds a configuration for Dial.

type Error

type Error struct {
	// Err is the wrapped error.
	Err error

	// Code is the error code.
	Code int

	// Constraint is the name of violated constraint.
	Constraint string

	// TableName is the name of the table.
	TableName string

	// ColumnName is the name of the column.
	ColumnName string

	// Message is the message returned by the DB.
	Message string
}

Error represents a wrapped query error.

func TranslateError

func TranslateError(err error) *Error

TranslateError tries to cast given error instance to PgError and extract enough information to build Error instance.

Jump to

Keyboard shortcuts

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