datastore

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB added in v0.14.0

func NewDB(dsn PGDatasourceName, logger zerolog.Logger) (*sql.DB, func(), error)

NewDB returns an open database handle of 0 or more underlying PostgreSQL connections

func NewNullInt64 added in v0.18.0

func NewNullInt64(i int64) sql.NullInt64

NewNullInt64 returns a null if i == 0, otherwise it returns the int64 which was input

func NewNullString added in v0.18.0

func NewNullString(s string) sql.NullString

NewNullString returns a null if s is empty, otherwise it returns the string which was input

Types

type Datastore

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

Datastore is a concrete implementation for a sql database

func NewDatastore added in v0.13.0

func NewDatastore(db *sql.DB) *Datastore

NewDatastore is an initializer for the Datastore struct

func (*Datastore) BeginTx

func (ds *Datastore) BeginTx(ctx context.Context) (*sql.Tx, error)

BeginTx is a wrapper for sql.DB.BeginTx in order to expose from the Datastore interface

func (*Datastore) CommitTx

func (ds *Datastore) CommitTx(tx *sql.Tx) error

CommitTx is a wrapper for sql.Tx.Commit in order to expose from the Datastore interface. Proper error handling is also considered.

func (*Datastore) DB added in v0.15.0

func (ds *Datastore) DB() *sql.DB

DB returns the sql.Db for the Datastore struct

func (*Datastore) RollbackTx

func (ds *Datastore) RollbackTx(tx *sql.Tx, err error) error

RollbackTx is a wrapper for sql.Tx.Rollback in order to expose from the Datastore interface. Proper error handling is also considered.

type Datastorer added in v0.15.0

type Datastorer interface {
	// DB returns a sql.DB
	DB() *sql.DB
	// BeginTx starts a sql.Tx using the input context
	BeginTx(context.Context) (*sql.Tx, error)
	// RollbackTx rolls back the input sql.Tx
	RollbackTx(*sql.Tx, error) error
	// CommitTx commits the Tx
	CommitTx(*sql.Tx) error
}

Datastorer is an interface for working with the Database

type PGDatasourceName added in v0.19.0

type PGDatasourceName struct {
	Host     string
	Port     int
	DBName   string
	User     string
	Password string
}

PGDatasourceName is a Postgres datasource name

func NewPGDatasourceName added in v0.19.0

func NewPGDatasourceName(host, dbname, user, password string, port int) PGDatasourceName

NewPGDatasourceName is an initializer for PGDatasourceName, which is a struct that holds the PostgreSQL datasource name details.

func (PGDatasourceName) String added in v0.19.0

func (dsn PGDatasourceName) String() string

String returns a formatted PostgreSQL datasource name. If you are using a local db with no password, it removes the password from the string, otherwise the connection will fail.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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