docs

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package docs defines a schema for storing documents in a kv.Txn.

This package is an example of using the kv package and its included kvschema command line tool to generate a strongly-typed API for storing documents as components associated with entities in a key-value store.

Index

Constants

View Source
const (
	// DocumentPrefix is a unique identifier for the Document component in this schema.
	DocumentPrefix kv.Component = 3

	// TitlePrefix is a unique identifier for the Title component in this schema.
	TitlePrefix kv.Component = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Title   string
	Content string
}

Document is a component value type.

func (*Document) Decode

func (d *Document) Decode(src []byte) error

Decode implements kv.Decoder for retrieving documents from a kv.Txn.

The presence of Encode and Decode methods tells kvschema to produce the DocumentComponent type.

func (*Document) Encode

func (d *Document) Encode() []byte

Encode implements kv.Encoder for storing documents in a kv.Txn.

The presence of Encode and Decode methods tells kvschema to produce the DocumentComponent type.

func (*Document) IndexTitle

func (d *Document) IndexTitle() []kv.String

IndexTitle provides values that should be mapped back to this document through an index.

The presence of a method whose name begins with "Index" and continues with "Title" tells kvschema to define a DocumentTitleIndex type.

type Txn

type Txn struct{ kv.Partitioned }

Txn provides entities, components, and indexes backed by a key-value store.

func New

func New(t kv.Txn) Txn

func (Txn) AllDocumentEntities

func (s Txn) AllDocumentEntities(start *kv.Entity, n int) (es []kv.Entity, err error)

AllDocumentEntities returns the first n entities that have a Document, beginning with the first entity greater than or equal to *start.

A nil start value will be interpreted as a pointer to zero.

A value of n less than or equal to zero will be interpretted as the largest possible value.

func (Txn) DeleteDocument

func (s Txn) DeleteDocument(e kv.Entity) error

DeleteDocument deletes the Document associated with e.

Corresponding indexes are updated.

func (Txn) EntitiesByDocumentTitle

func (s Txn) EntitiesByDocumentTitle(cursor *kv.IndexCursor, n int) (es []kv.Entity, err error)

EntitiesByDocumentTitle returns entities with Document values ordered by the kv.String values from their IndexTitle method.

Reading begins at cursor, and ends when the length of the returned Entity slice is less than n. When reading is not complete, cursor is updated such that using it in a subequent call to ByTitle would return next n entities.

func (Txn) EntitiesMatchingDocumentTitle

func (s Txn) EntitiesMatchingDocumentTitle(v kv.String) (kv.EntitySlice, error)

EntitiesMatchingDocumentTitle returns entities with Document values that return a matching kv.String from their IndexTitle method.

The returned EntitySlice is already sorted.

func (Txn) GetDocument

func (s Txn) GetDocument(e kv.Entity) (Document, error)

GetDocument returns the Document associated with e.

If no Document has been explicitly set for e, and GetDocument will return the result of decoding a Document from an empty slice of bytes.

func (Txn) GetDocumentSlice

func (s Txn) GetDocumentSlice(es []kv.Entity) ([]Document, error)

GetDocumentSlice returns a Document for each entity in es.

If no Document has been explicitly set for an entity, and the result will be a Document that has been decoded from an empty slice of bytes.

func (Txn) SetDocument

func (s Txn) SetDocument(e kv.Entity, v *Document) error

SetDocument sets the Document associated with e to v.

Corresponding indexes are updated.

Jump to

Keyboard shortcuts

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