store

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

go-store

High-performance persistence library for internal Go apps.

Installation

go-store may be installed using the go get command:

go get github.com/pghq/go-store

Usage

A typical usage scenario:

import (
    "context"
    
    "github.com/pghq/go-store"
)

// Create an instance
db, err := store.New()
if err != nil{
    panic(err)
}

// Add some data
err := db.Do(context.TODO(), func(tx store.Txn) error {
    return tx.Add("tests", map[string]interface{}{"id": "1234"})
})

if err != nil{
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchConfig added in v1.2.0

type BatchConfig struct {
	QueryTTL time.Duration
}

BatchConfig configuration for store batch operations

type BatchOption added in v1.2.0

type BatchOption func(conf *BatchConfig)

BatchOption for customizing store batch operations

func QueryTTL

func QueryTTL(duration time.Duration) BatchOption

QueryTTL custom duration of time to cache queries for

type Config

type Config struct {
	DSN       string
	Migration fs.ReadDirFS
	PgOptions []pg.Option
}

Config a configuration for the store

type Option

type Option func(conf *Config)

Option A store configuration option

func WithDSN

func WithDSN(dsn string) Option

WithDSN Use dsn

func WithMigration

func WithMigration(fs fs.ReadDirFS) Option

WithMigration Use database migration

func WithPg

func WithPg(opts ...pg.Option) Option

WithPg Use custom pg options

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store an abstraction over database persistence

func New

func New(opts ...Option) (*Store, error)

New creates a new instance of the data store

func NewStore

func NewStore(db db.DB) *Store

NewStore creates a new store instance

func (Store) Add

func (s Store) Add(ctx context.Context, collection string, v interface{}) error

Add appends a value to the collection

func (Store) All

func (s Store) All(ctx context.Context, spec db.Spec, v interface{}, opts ...BatchOption) error

All retrieves a listing of values

func (Store) Batch added in v1.0.3

func (s Store) Batch(ctx context.Context, batch db.Batch, opts ...BatchOption) error

Batch query

func (Store) Begin

func (s Store) Begin(ctx context.Context, opts ...db.TxOption) (Txn, error)

Begin a transaction

func (Store) Do

func (s Store) Do(ctx context.Context, fn func(tx Txn) error, opts ...db.TxOption) error

Do execute callback in a transaction

func (Store) Edit

func (s Store) Edit(ctx context.Context, collection string, spec db.Spec, v interface{}) error

Edit updates value(s) in the collection

func (Store) One

func (s Store) One(ctx context.Context, spec db.Spec, v interface{}, opts ...BatchOption) error

One retrieve the first value matching the spec

func (Store) Remove

func (s Store) Remove(ctx context.Context, collection string, spec db.Spec) error

Remove deletes values(s) in the collection

type Txn

type Txn struct {
	// contains filtered or unexported fields
}

Txn A unit of work

func (*Txn) Add

func (tx *Txn) Add(collection string, v interface{}) error

Add appends a value to the collection

func (*Txn) All

func (tx *Txn) All(spec db.Spec, v interface{}, opts ...BatchOption) error

All retrieves a listing of values

func (*Txn) Batch added in v1.0.3

func (tx *Txn) Batch(batch db.Batch, opts ...BatchOption) error

Batch performs a batch query op within a transaction

func (*Txn) Context

func (tx *Txn) Context() context.Context

Context gets the context of the transaction

func (*Txn) Edit

func (tx *Txn) Edit(collection string, spec db.Spec, v interface{}) error

Edit updates value(s) in the collection

func (*Txn) One

func (tx *Txn) One(spec db.Spec, v interface{}, opts ...BatchOption) error

One retrieve the first value matching the spec

func (*Txn) Remove

func (tx *Txn) Remove(collection string, spec db.Spec) error

Remove deletes values(s) in the collection

Directories

Path Synopsis
db
pg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL