Go · Documents

Documents

import "github.com/unum-cloud/ustore" 1.0.0-rc.1 · 084197c4

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ustore/go/documents.md' | claude -p "How would this fit my code?"

DocsWrite writes JSON text by default, whole documents or, with Fields, top-level keys and RFC 6901 pointers inside them, and DocsModification chooses between an upsert, an update, an insert, an RFC 6902 patch and an RFC 7386 merge. DocsRead reads whole documents or fields as JSON or as strings, and DocsGist lists the paths to every leaf. DocsGather converts fields into typed columns, a row per key, whose scalars DocsColumnScalars views straight in the arena beside the validity, conversion and collision bitmaps.

documents := ustore.TapeOf(`{"name":"Ada","born":1815}`)
err := database.DocsWrite(people, []ustore.Key{ada}, documents, nil)
died := &ustore.DocsWriteConfig{Fields: ustore.TapeOf("died")}
err = database.DocsWrite(people, []ustore.Key{ada}, ustore.TapeOf("1852"), died)

names, err := database.DocsRead(people, []ustore.Key{ada}, arena, &ustore.DocsReadConfig{
	Fields: ustore.TapeOf("name"), OutputsType: ustore.DocsFieldTypeString,
})
paths, err := database.DocsGist(people, []ustore.Key{ada}, otherArena)
columns, err := database.DocsGather(people, []ustore.Key{ada}, ustore.TapeOf("born"),
	[]ustore.DocsFieldType{ustore.DocsFieldTypeU64}, arena)
born := ustore.DocsColumnScalars[uint64](columns.Column(0))

API

Types

DocsReadConfigDocsReadConfig carries the optional arguments of DatabaseOn.DocsRead.
db.go:231 ↗
type DocsReadConfig struct {
    Fields Tape
    OutputsType DocsFieldType
}

Fields

FieldsTapeFields to read inside the documents, one per key, top-level keys or RFC 6901 pointers, or whole documents when empty.
OutputsTypeDocsFieldTypeOutputsType is what the values are converted into, JSON text by default or a string.
DocsScalarDocsScalar constrains the Go types a scalar column reads as, one per fixed-width DocsFieldType: a 16-bit float as its bits, and a UUID as a Key.
db.go:407 ↗
type DocsScalar interface {
    ~bool | ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~[16]byte
}
DocsWriteConfigDocsWriteConfig carries the optional arguments of DatabaseOn.DocsWrite.
db.go:127 ↗
type DocsWriteConfig struct {
    IDField string
    Fields Tape
    Type DocsFieldType
    Modification DocsModification
    Durability Durability
}

Fields

IDFieldstringIDField is the field holding the key of every document when no keys are given, such as "_id".
FieldsTapeFields to modify inside the documents, one per task, or whole documents when empty.
TypeDocsFieldTypeType is the format of the written values, JSON text by default.
ModificationDocsModificationModification is applied to every document, an upsert by default.
DurabilityDurabilityDurability is how durable the writes are once the call finishes at the head.
StructColumnsColumns is one typed column per field a gather converted, one row per document, readable until the arena serves another call.2
docs.go:345 ↗
type Columns struct {
    // contains filtered or unexported fields
}
ColumnColumn reports the column of field index.
docs.go:356 ↗
func (columns Columns) Column(index uint) DocsColumn
LenLen reports how many columns the call gathered, one per field.
docs.go:353 ↗
func (columns Columns) Len() uint
StructDocsBatchesDocsBatches is what one pull of a DocsCursor wrote into its arena in walk order, one batch per executor task that found rows, readable until the arena serves another call.3
docs.go:628 ↗
type DocsBatches struct {
    // contains filtered or unexported fields
}
ColumnsColumns views the columns of batch index in the arena, one per field the cursor gathers.
docs.go:647 ↗
func (batches DocsBatches) Columns(index uint) Columns
KeysKeys views the keys of batch index in the arena, one per row.
docs.go:639 ↗
func (batches DocsBatches) Keys(index uint) []Key
LenLen reports how many batches the pull handed out, none once the walk is exhausted.
docs.go:636 ↗
func (batches DocsBatches) Len() uint
StructDocsColumnDocsColumn is the rows of one field as an Apache Arrow array of its type, beside the bitmaps of the rows found and converted, converted with a change of semantics, and colliding with a value of an inconvertible type.5
docs.go:366 ↗
type DocsColumn struct {
    // contains filtered or unexported fields
}
CollidingColliding reports whether a value of an inconvertible type sits under row's field.
docs.go:391 ↗
func (column DocsColumn) Colliding(row uint) bool
ConvertedConverted reports whether row's conversion changed its semantics, such as a string parsed into an integer.
docs.go:384 ↗
func (column DocsColumn) Converted(row uint) bool
LenLen reports how many rows the column holds.
docs.go:373 ↗
func (column DocsColumn) Len() uint
StringsStrings views the rows of a string, binary or JSON column in the arena, and nothing for a scalar column.
docs.go:399 ↗
func (column DocsColumn) Strings() Strings
ValidValid reports whether row's value was found and converted.
docs.go:376 ↗
func (column DocsColumn) Valid(row uint) bool
EnumDocsFieldTypeDocsFieldType is the type of a document, or of a value extracted from one; every type but JSON text, strings and binary text is a fixed-width scalar.2
docs.go:42 ↗
type DocsFieldType int32

Values

DocsFieldTypeJSONDocsFieldTypeJSON is JSON text.
DocsFieldTypeNullDocsFieldTypeNull is the JSON null.
DocsFieldTypeBoolDocsFieldTypeBool is a boolean.
DocsFieldTypeUUIDDocsFieldTypeUUID is a 128-bit UUID.
DocsFieldTypeF64DocsFieldTypeF64 is a 64-bit float.
DocsFieldTypeF32DocsFieldTypeF32 is a 32-bit float.
DocsFieldTypeF16DocsFieldTypeF16 is a 16-bit float.
DocsFieldTypeI64DocsFieldTypeI64 is a signed 64-bit integer.
DocsFieldTypeI32DocsFieldTypeI32 is a signed 32-bit integer.
DocsFieldTypeI16DocsFieldTypeI16 is a signed 16-bit integer.
DocsFieldTypeI8DocsFieldTypeI8 is a signed 8-bit integer.
DocsFieldTypeU64DocsFieldTypeU64 is an unsigned 64-bit integer.
DocsFieldTypeU32DocsFieldTypeU32 is an unsigned 32-bit integer.
DocsFieldTypeU16DocsFieldTypeU16 is an unsigned 16-bit integer.
DocsFieldTypeU8DocsFieldTypeU8 is an unsigned 8-bit integer.
DocsFieldTypeBinaryDocsFieldTypeBinary is the text of a value without a null terminator.
DocsFieldTypeStringDocsFieldTypeString is a value printed as text.
DocsFieldTypeFromNameDocsFieldTypeFromName reads a field type back from the spelling DocsFieldType.String renders.
docs.go:87 ↗
func DocsFieldTypeFromName(name string) (DocsFieldType, error)
StringString renders the field type as the library spells it, such as "f64".
docs.go:82 ↗
func (fieldType DocsFieldType) String() string
EnumDocsModificationDocsModification is the modification a document write applies.2
docs.go:94 ↗
type DocsModification int32

Values

DocsModifyUpsertDocsModifyUpsert writes whether or not the document exists.
DocsModifyUpdateDocsModifyUpdate writes only documents that exist.
DocsModifyInsertDocsModifyInsert writes only documents that do not exist.
DocsModifyPatchDocsModifyPatch applies an RFC 6902 patch.
DocsModifyMergeDocsModifyMerge applies an RFC 7386 merge.
DocsModificationFromNameDocsModificationFromName reads a modification back from the spelling DocsModification.String renders.
docs.go:116 ↗
func DocsModificationFromName(
    name string,
) (DocsModification, error)
StringString renders the modification as the library spells it.
docs.go:110 ↗
func (modification DocsModification) String() string
StructPathsPaths is every unique JSON Pointer to a leaf that a gist found, readable until the arena serves another call.2
docs.go:284 ↗
type Paths struct {
    // contains filtered or unexported fields
}
GetGet views path index in the arena.
docs.go:294 ↗
func (paths Paths) Get(index uint) []byte
LenLen reports how many unique paths the call found.
docs.go:291 ↗
func (paths Paths) Len() uint

Functions

DocsColumnScalarsDocsColumnScalars views the scalars of a column gathered as the type Value spells, in place; a Value of another width than the column's type reads garbage, as the column does not record it.
ustore.go:413 ↗
func DocsColumnScalars[Value DocsScalar](
    column DocsColumn,
) []Value
DocsColumnViewToArrowDocsColumnViewToArrow exports one column a gather of fieldType wrote into arena as an Arrow column whose validity buffer is the column's validities; until both outputs are released, the arena's next call and Close answer StatusContended.
ustore.go:118 ↗
func DocsColumnViewToArrow(
    column DocsColumn,
    fieldType DocsFieldType,
    arena *Arena,
    schema *ArrowSchema,
    array *ArrowDeviceArray,
) error