store

package
v0.0.0-...-e10204a Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Mut

type Mut struct {
	RecordID string
	Author   string
	Reason   string
	Ops      []Op
}

type OneOpts

type OneOpts struct {
	ID     string `json:"id,omitempty"`
	Kind   string `json:"kind,omitempty"`
	Attr   string `json:"attr,omitempty"`
	Follow string `json:"follow,omitempty"`
}

type Op

type Op struct {
	Name string `json:"name"`
	Args any    `json:"args,omitempty"`
}

TODO make ops opaque

func AddRec

func AddRec(kind string, attrs any) Op

func AddRel

func AddRel(id, kind, to string, attrs any) Op

func ClearAttrs

func ClearAttrs() Op

func DelAttr

func DelAttr(key string) Op

func DelRel

func DelRel(id string) Op

func SetAttr

func SetAttr(key string, val any) Op

type Query

type Query struct {
	Limit  int      `json:"-"`
	Offset int      `json:"-"`
	ID     string   `json:"id,omitempty"`
	IDIn   []string `json:"id_in,omitempty"`
	Kind   string   `json:"kind,omitempty"`
	Attr   string   `json:"attr,omitempty"`
	Follow string   `json:"follow,omitempty"`
}

type Record

type Record struct {
	ID         string          `json:"id"`
	Kind       string          `json:"kind"`
	Attributes json.RawMessage `json:"attributes"`
	Relations  []*Relation     `json:"relations"`
	CreatedAt  time.Time       `json:"created_at"`
	UpdatedAt  time.Time       `json:"updated_at"`
}

type Relation

type Relation struct {
	ID         string          `json:"id"`
	Kind       string          `json:"kind"`
	Attributes json.RawMessage `json:"attributes"`
	Record     *Record         `json:"record"`
	CreatedAt  time.Time       `json:"created_at"`
	UpdatedAt  time.Time       `json:"updated_at"`
}

type Store

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

func New

func New(ctx context.Context, conn string) (*Store, error)

func NewFromPool

func NewFromPool(pool *pgxpool.Pool) (*Store, error)

func (*Store) Many

func (s *Store) Many(ctx context.Context, query Query) ([]*Record, error)

func (*Store) Mutate

func (s *Store) Mutate(ctx context.Context, muts ...Mut) error

TODO optimistic locking

func (*Store) One

func (s *Store) One(ctx context.Context, opts OneOpts) (*Record, error)

Jump to

Keyboard shortcuts

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