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 ¶
- func NewNullInt64(i int64) sql.NullInt64
- func NewNullString(s string) sql.NullString
- func NewNullUUID(id uuid.UUID) uuid.NullUUID
- 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 NewNullUUID ¶ added in v0.39.0
NewNullUUID returns a null if id == uuid.Nil, otherwise it returns the uuid.UUID which was input as an uuid.NullUUID type
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 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 Pool Ping method.
|
Package pingstore enables database health checks through the db Pool Ping method. |