datastore

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 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 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 DefaultDatastore added in v0.20.0

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

DefaultDatastore is a concrete implementation for a sql database

func NewDefaultDatastore added in v0.20.0

func NewDefaultDatastore(db *sql.DB) DefaultDatastore

NewDefaultDatastore is an initializer for the default Datastore struct

func (DefaultDatastore) BeginTx added in v0.20.0

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

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

func (DefaultDatastore) CommitTx added in v0.20.0

func (ds DefaultDatastore) 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 (DefaultDatastore) DB added in v0.20.0

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

DB returns the sql.Db for the Datastore struct

func (DefaultDatastore) RollbackTx added in v0.20.0

func (ds DefaultDatastore) 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 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
Package datastoretest is for datastore helper functions
Package datastoretest is for datastore helper functions

Jump to

Keyboard shortcuts

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