Documentation
¶
Overview ¶
Package datastore is used to interact with a datastore. It has functions to help setup a sql.DB as well as helpers for working with the sql.DB once it's initialized.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDB ¶ added in v0.14.0
NewDB returns an open database handle of 0 or more underlying PostgreSQL connections
func NewNullInt64 ¶ added in v0.18.0
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
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
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 provides testing helper functions for the datastore package.
|
Package datastoretest provides testing helper functions for the datastore package. |
|
Package moviestore performs all DML and select operations for a movie
|
Package moviestore performs all DML and select operations for a movie |
|
Package pingstore enables database health checks through the db PingContext method.
|
Package pingstore enables database health checks through the db PingContext method. |