Documentation ¶
Index ¶
- Variables
- func ApplyAll[T any](t *T, opts ...func(*T))
- func WithSerializer[D any, K AnyBytes](serializer Serializer[D]) func(*Collection[D, K])
- type AnyBytes
- type Collection
- type CollectionSchema
- type CollectionUpdate
- func (c CollectionUpdate[D, K]) Delete(ctx context.Context, doc D) error
- func (c CollectionUpdate[D, K]) Fetch(ctx context.Context, key K) (d D, err error)
- func (c CollectionUpdate[D, K]) List(ctx context.Context, pred ListPredicate) ([]D, error)
- func (c CollectionUpdate[D, K]) Put(ctx context.Context, doc D) error
- type CollectionView
- type JSONSerializer
- type ListPredicate
- type Options
- type Schema
- type Serializer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = errors.New("document not found")
Functions ¶
func WithSerializer ¶
func WithSerializer[D any, K AnyBytes](serializer Serializer[D]) func(*Collection[D, K])
Types ¶
type Collection ¶
Example ¶
package main import ( "context" "github.com/georgemac/dokvs/pkg/kv" ) type ID string var ( schema = NewSchema("recipes", func(r Recipe) []byte { return []byte(r.ID) }) serializer Serializer[Recipe] = (JSONSerializer[Recipe]{}) ) type Recipe struct { ID ID } func main() { recipes := NewCollection[Recipe, ID](schema, WithSerializer[Recipe, ID](serializer)) ctx := context.Background() var update kv.Update recipesUpdate, _ := recipes.Update(update) _ = recipesUpdate.Put(ctx, Recipe{ID: "my_recipe"}) var view kv.View recipesView, _ := recipes.View(view) _, _ = recipesView.Fetch(ctx, ID("my_recipe")) }
Output:
func NewCollection ¶
func NewCollection[D any, K AnyBytes](schema CollectionSchema[D], opts ...func(*Collection[D, K])) Collection[D, K]
func (Collection[D, K]) Update ¶
func (c Collection[D, K]) Update(update kv.Update) (cu CollectionUpdate[D, K], err error)
func (Collection[D, K]) View ¶
func (c Collection[D, K]) View(view kv.View) (cv CollectionView[D, K], err error)
type CollectionSchema ¶
type CollectionUpdate ¶
type CollectionUpdate[D any, K AnyBytes] struct { CollectionView[D, K] // contains filtered or unexported fields }
func (CollectionUpdate[D, K]) Delete ¶
func (c CollectionUpdate[D, K]) Delete(ctx context.Context, doc D) error
func (CollectionUpdate[D, K]) Fetch ¶
func (c CollectionUpdate[D, K]) Fetch(ctx context.Context, key K) (d D, err error)
func (CollectionUpdate[D, K]) List ¶
func (c CollectionUpdate[D, K]) List(ctx context.Context, pred ListPredicate) ([]D, error)
type CollectionView ¶
type CollectionView[D any, K AnyBytes] struct { Collection[D, K] // contains filtered or unexported fields }
func (CollectionView[D, K]) Fetch ¶
func (c CollectionView[D, K]) Fetch(ctx context.Context, key K) (d D, err error)
func (CollectionView[D, K]) List ¶
func (c CollectionView[D, K]) List(ctx context.Context, pred ListPredicate) (ds []D, err error)
type JSONSerializer ¶
type JSONSerializer[T any] struct{}
func (JSONSerializer[T]) Deserialize ¶
func (d JSONSerializer[T]) Deserialize(v []byte, t *T) error
func (JSONSerializer[T]) Serialize ¶
func (s JSONSerializer[T]) Serialize(t T) ([]byte, error)
type ListPredicate ¶
type Schema ¶
type Schema[D any] struct { // contains filtered or unexported fields }
func (Schema[D]) Collection ¶
func (Schema[D]) PrimaryKey ¶
Click to show internal directories.
Click to hide internal directories.