Documentation ¶
Index ¶
- type DB
- func (d *DB) Close() error
- func (d *DB) Get(ctx context.Context, key string) ([]byte, error)
- func (d *DB) GetKeys(ctx context.Context, prefix string) ([]string, error)
- func (d *DB) NewTransaction(ctx context.Context, update bool) (database.Transaction, context.Context, error)
- func (d *DB) Set(ctx context.Context, key string, value []byte) error
- type Txn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements the database.DB interface by storing data in Postgres. All the data is stored in a single table that acts as a key/value store.
func New ¶
New connects to Postgres and creates the target table if it does not exist. It returns a *DB with a pool of connections used for future interactions with Postgres. Close needs to be called before exiting to close any open connections.
Refer to pgxpool.ParseConfig for details about the connection string format.
# Example DSN user=jack password=secret host=pg.example.com port=5432 dbname=mydb sslmode=verify-ca pool_max_conns=10 # Example URL postgres://jack:secret@pg.example.com:5432/mydb?sslmode=verify-ca&pool_max_conns=10
func (*DB) Get ¶
Get returns the value stored under the key. If no value is found it returns database.ErrKeyNotExist.
func (*DB) GetKeys ¶
GetKeys returns all keys with the requested prefix. If prefix is an empty string it will return all keys.
func (*DB) NewTransaction ¶
func (d *DB) NewTransaction(ctx context.Context, update bool) (database.Transaction, context.Context, error)
NewTransaction starts a new transaction. The `update` parameter controls the access mode ("read only" or "read write"). It returns the transaction as well as a context that contains the transaction. Passing the context in future calls to *DB will execute that action in that transaction.