Documentation
¶
Overview ¶
Package datastore is used to interact with a datastore. It has functions to help set up a sql.DB as well as helpers for working with the sql.DB once it's initialized.
Index ¶
- Constants
- func NewNullInt32(i int32) sql.NullInt32
- func NewNullInt64(i int64) sql.NullInt64
- func NewNullString(s string) sql.NullString
- func NewNullTime(t time.Time) sql.NullTime
- func NewPostgreSQLPool(ctx context.Context, dsn PostgreSQLDSN, logger zerolog.Logger) (*pgxpool.Pool, func(), error)
- func ValidatePostgreSQLPool(ctx context.Context, pool *pgxpool.Pool, log zerolog.Logger) error
- type Datastore
- type PostgreSQLDSN
Constants ¶
const ( // DBHostEnv is the database host environment variable name DBHostEnv string = "DB_HOST" // DBPortEnv is the database port environment variable name DBPortEnv string = "DB_PORT" // DBNameEnv is the database name environment variable name DBNameEnv string = "DB_NAME" // DBUserEnv is the database user environment variable name DBUserEnv string = "DB_USER" // DBPasswordEnv is the database user password environment variable name DBPasswordEnv string = "DB_PASSWORD" // DBSearchPathEnv is the database search path environment variable name DBSearchPathEnv string = "DB_SEARCH_PATH" )
Variables ¶
This section is empty.
Functions ¶
func NewNullInt32 ¶ added in v0.40.0
NewNullInt32 returns a null if i == 0, otherwise it returns the int32 which was input.
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
func NewNullTime ¶ added in v0.40.0
NewNullTime returns a null if t is the zero value for time.Time, otherwise it returns the time which was input
func NewPostgreSQLPool ¶ added in v0.38.0
func NewPostgreSQLPool(ctx context.Context, dsn PostgreSQLDSN, logger zerolog.Logger) (*pgxpool.Pool, func(), error)
NewPostgreSQLPool returns an open database handle of 0 or more underlying PostgreSQL connections
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
NewDatastore is an initializer for the Datastore struct
func (Datastore) BeginTx ¶
BeginTx returns an acquired transaction from the db pool and adds app specific error handling
func (Datastore) CommitTx ¶
CommitTx is a wrapper for sql.Tx.Commit in order to expose from the Datastore interface. Proper error handling is also considered.
type PostgreSQLDSN ¶ added in v0.34.0
type PostgreSQLDSN struct {
Host string
Port int
DBName string
SearchPath string
User string
Password string
}
PostgreSQLDSN is a PostgreSQL datasource name
func (PostgreSQLDSN) ConnectionURI ¶ added in v0.39.0
func (dsn PostgreSQLDSN) ConnectionURI() string
ConnectionURI returns a formatted PostgreSQL datasource "Keyword/Value Connection String" The general form for a connection URI is: postgresql://[userspec@][hostspec][/dbname][?paramspec] where userspec is
user[:password]
and hostspec is:
[host][:port][,...]
and paramspec is:
name=value[&...]
The URI scheme designator can be either postgresql:// or postgres://. Each of the remaining URI parts is optional. The following examples illustrate valid URI syntax:
postgresql:// postgresql://localhost postgresql://localhost:5433 postgresql://localhost/mydb postgresql://user@localhost postgresql://user:secret@localhost postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp postgresql://host1:123,host2:456/somedb?target_session_attrs=any&application_name=myapp
func (PostgreSQLDSN) KeywordValueConnectionString ¶ added in v0.39.0
func (dsn PostgreSQLDSN) KeywordValueConnectionString() string
KeywordValueConnectionString returns a formatted PostgreSQL datasource "Keyword/Value Connection String"
Directories
¶
| Path | Synopsis |
|---|---|
|
Package datastoretest provides testing helper functions for the datastore package.
|
Package datastoretest provides testing helper functions for the datastore package. |
|
Package pingstore enables database health checks through the db Pool Ping method.
|
Package pingstore enables database health checks through the db Pool Ping method. |