postgres: Index | Files

package postgres

import ""

Package postgres defines Store, a Postgres client that partially implements the Store interface defined in "".


Package Files

doc.go options.go store.go

func WithCreateTable Uses

func WithCreateTable(db *sql.DB, tablename string) error

type Option Uses

type Option func(db *sql.DB, tablename string) error

type Store Uses

type Store struct {
    // contains filtered or unexported fields

Store holds the SQL statements prepared against a Postgresql table. Initialise with New.

func New Uses

func New(db *sql.DB, tablename string, options ...Option) (s Store, err error)

New creates a table of name tablename if it does not exist, and prepares statements against it. The table has two columms: "k" is the TEXT primary key and "v" is a JSONb column holding the values.

func (Store) Add Uses

func (s Store) Add(ctx context.Context, v json.Marshaler) (string, error)

Add persists a new object and returns its unique UUIDv4 key. Err is non-nil in case of failure.

func (Store) Close Uses

func (s Store) Close() (err error)

Close releases the resources associated with the Store. Returns the first error encountered while closing the prepared statements.

func (Store) Delete Uses

func (s Store) Delete(ctx context.Context, k string) error

func (Store) Get Uses

func (s Store) Get(ctx context.Context, k string, v json.Unmarshaler) (bool, error)

Get retrieves a new item by key and unmarshals it into v, or returns false if not found. Err is non-nil in case of failure.

func (Store) GetAll Uses

func (s Store) GetAll(ctx context.Context, c store.Collection) error

GetAll appends to c every item in the store. Err is non-nil in case of failure.

func (Store) Ping Uses

func (s Store) Ping(ctx context.Context) error

func (Store) Set Uses

func (s Store) Set(ctx context.Context, k string, v json.Marshaler) error

func (Store) Update Uses

func (s Store) Update(ctx context.Context, k string, v json.Marshaler) error

Update assigns the given value to the given key, if it exists. Err is non-nil if the key was not already present, or in case of failure.

Package postgres imports 5 packages (graph). Updated 2018-09-19. Refresh now. Tools for package owners.