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
- type Document
- type Txn
- func (s Txn) AllDocumentEntities(start *kv.Entity, n int) (es []kv.Entity, err error)
- func (s Txn) DeleteDocument(e kv.Entity) error
- func (s Txn) EntitiesByDocumentTitle(cursor *kv.IndexCursor, n int) (es []kv.Entity, err error)
- func (s Txn) EntitiesMatchingDocumentTitle(v kv.String) (kv.EntitySlice, error)
- func (s Txn) GetDocument(e kv.Entity) (Document, error)
- func (s Txn) GetDocumentSlice(es []kv.Entity) ([]Document, error)
- func (s Txn) SetDocument(e kv.Entity, v *Document) error
Constants ¶
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 ¶
Document is a component value type.
func (*Document) Decode ¶
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 ¶
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 ¶
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 (Txn) AllDocumentEntities ¶
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 ¶
DeleteDocument deletes the Document associated with e.
Corresponding indexes are updated.
func (Txn) EntitiesByDocumentTitle ¶
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 ¶
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 ¶
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 ¶
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.