sql

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UniqueViolationCode = "23505"
)

Variables

View Source
var (
	ErrNilQuery = errors.New("sql query cannot be nil")
	ErrNilRow   = errors.New("sql row cannot be nil")
)

Functions

func Close added in v0.4.6

func Close(db *sql.DB) error

Close closes the SQL connection

func Connect added in v0.4.6

func Connect(
	driverName, dataSourceName string,
	config *Config,
) (*sql.DB, error)

Connect returns a new SQL connection

func CreateTransaction

func CreateTransaction(db *sql.DB, fn func(tx *sql.Tx) error) error

CreateTransaction creates a transaction for the database

func IsUniqueViolationError added in v0.4.3

func IsUniqueViolationError(err error) (bool, string)

IsUniqueViolationError checks if the error is a unique violation error

Types

type Config added in v0.4.6

type Config struct {
	DB                    *sql.DB
	MaxOpenConnections    *int
	MaxIdleConnections    *int
	ConnectionMaxLifetime *time.Duration
}

Config struct

func NewConfig added in v0.4.6

func NewConfig(
	maxOpenConnections *int,
	maxIdleConnections *int,
	connectionMaxLifetime *time.Duration,
) *Config

NewConfig creates a new configuration

func (*Config) Close added in v0.4.6

func (c *Config) Close(db *sql.DB) error

Close closes the SQL connection

func (*Config) Connect added in v0.4.6

func (c *Config) Connect(
	driverName, dataSourceName string,
) (*sql.DB, error)

Connect returns a new SQL connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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