sql

package
v0.0.0-...-7ffd827 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxOpenConns int           = 25
	DefaultMaxIdleConns int           = 5
	DefaultMaxLifetime  time.Duration = 5 * time.Minute
	DefaultMaxIdleTime  time.Duration = 5 * time.Minute
)

Default values for configuring the DB connection pool. Values taken from https://www.alexedwards.net/blog/configuring-sqldb - accessed 2023/01/28.

Variables

View Source
var ErrNoRows = sql.ErrNoRows

Functions

This section is empty.

Types

type Config

type Config struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Protocol string `json:"protocol"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	DBName   string `json:"db_name"`
	Dialect  string `json:"dialect"`
}

Config provides a database configuration. Not all fields will be used dependent on database dialect being used.

func DefaultConfig

func DefaultConfig() Config

func (Config) DSN

func (cfg Config) DSN() string

DSN returns a dsn string for the selected database dialect specified by the config. Supports mysql and postgres syntax but others can be added.

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func Open

func Open(cfg Config) (*DB, error)

Open is a convenience function that wraps sql.Open to establish a connection to the DB and verifies the connection, in one step, as well as setting sensible default values for the connection pool.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTx wraps the sql.BeginTx and sets a tx time.

func (*DB) DestructiveReset

func (db *DB) DestructiveReset() error

func (*DB) MigrateDown

func (db *DB) MigrateDown() error

func (*DB) MigrateUp

func (db *DB) MigrateUp() error

func (*DB) SetMigrationPath

func (db *DB) SetMigrationPath(pathToMigrationFiles string)

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

func (*Tx) Now

func (tx *Tx) Now() time.Time

Now returns the time that the Tx started at.

Jump to

Keyboard shortcuts

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