document

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SchemaVersion specifies a latest schema version.
	SchemaVersion = 1
)

Variables

View Source
var (
	ErrNotSupported = errors.New("not supported")
	ErrInvalid      = errors.New("invalid")
	ErrNotExist     = errors.New("not exist")
)

Functions

func NewErrObjectNotExist added in v1.3.0

func NewErrObjectNotExist(key Key) error

NewErrObjectNotExist returns a new error that the object is not exist.

func NewErrPrimaryIndexNotExist added in v1.0.3

func NewErrPrimaryIndexNotExist() error

NewErrPrimaryIndexNotExist returns a new error that the primary index is not exist.

func NewValueForSchema added in v1.0.1

func NewValueForSchema(schema Schema, name string, av any) (any, error)

NewValueForSchema returns a value for the specified schema.

func NewValueForType added in v1.0.1

func NewValueForType(et ElementType, av any) (any, error)

NewValueForType returns a value for the specified element type.

Types

type Coder added in v0.9.0

type Coder interface {
	Decoder
	Encoder
}

A Coder includes decoder and encoder interfaces.

type Collection added in v0.9.0

type Collection interface {
	Schema
}

Collection represents a collection.

func NewCollection added in v0.9.0

func NewCollection() Collection

NewCollection returns a blank collection.

func NewCollectionWith added in v0.9.0

func NewCollectionWith(obj any) (Collection, error)

NewCollectionWith returns a new collection with the specified object.

type Decoder

type Decoder interface {
	// DecodeDocument returns the decorded object from the specified reader if available, otherwise returns an error.
	DecodeDocument(r io.Reader) (Object, error)
}

An Decoder reads encorded objects from the specified input stream.

type Element

type Element interface {
	// Name returns the unique name.
	Name() string
	// Type returns the index type.
	Type() ElementType
	// Data returns the raw representation data in memory.
	Data() any
	// SetName sets the specified name to the element.
	SetName(name string) Element
	// SetType sets the specified type to the element.
	SetType(t ElementType) Element
}

func NewElement

func NewElement() Element

NewElement returns a blank element.

type ElementType

type ElementType int8
const (
	// 0x0x (Reserved).
	// 0x1x (Reserved - Collection).
	ArrayType ElementType = 0x10
	MapType   ElementType = 0x11
	// 0x20 Integer.
	Int8Type  ElementType = 0x20
	Int16Type ElementType = 0x21
	Int32Type ElementType = 0x22
	Int64Type ElementType = 0x23
	// 0x30 StringType.
	StringType ElementType = 0x30
	BinaryType ElementType = 0x31
	// 0x40 Floating-point.
	Float32Type ElementType = 0x40
	Float64Type ElementType = 0x41
	// 0x70 Special.
	DatetimeType ElementType = 0x70
	BoolType     ElementType = 0x71
)

func NewElementTypeWith

func NewElementTypeWith(v any) (ElementType, error)

NewElementTypeWith returns an element type from the specified parameters.

func (ElementType) String

func (et ElementType) String() string

String represents the string representation.

type Elements added in v1.0.0

type Elements []Element

Elements represents a list of Element.

func (Elements) Len added in v1.0.0

func (elems Elements) Len() int

Len returns the number of elements.

func (Elements) Names added in v1.0.0

func (elems Elements) Names() []string

Names returns the element names.

type Encoder

type Encoder interface {
	// EncodeDocument writes the specified object to the specified writer.
	EncodeDocument(w io.Writer, obj Object) error
}

An Encoder writes the specified object to the specified output stream.

type Index

type Index interface {
	// Name returns the unique name.
	Name() string
	// Type returns the index type.
	Type() IndexType
	// Elements returns the schema elements.
	Elements() []Element
	// SetName sets the specified name to the index.
	SetName(name string) Index
	// SetType sets the specified type to the element.
	SetType(t IndexType) Index
	// AddElement returns the schema elements.
	AddElement(elem Element) Index
	// Data returns the raw representation data in memory.
	Data() any
}

func NewIndex

func NewIndex() Index

NewIndex returns a blank index.

type IndexType

type IndexType = uint8
const (
	PrimaryIndex   IndexType = 1
	SecondaryIndex IndexType = 2
)

type Indexes added in v1.0.0

type Indexes []Index

Indexes represents a list of Index.

func (Indexes) Len added in v1.0.0

func (idxs Indexes) Len() int

Len returns the number of indexes.

type Key

type Key []any

Key represents an unique key for a document object.

func NewKey

func NewKey() Key

NewKey returns a new blank key.

func NewKeyWith

func NewKeyWith(elems ...any) Key

NewKeyWith returns a new key from the specified key elements.

func (Key) Collection added in v1.0.0

func (key Key) Collection() (string, error)

Collection returns the collection name of the key.

func (Key) Database added in v1.0.0

func (key Key) Database() (string, error)

Database returns the database name of the key.

func (Key) Elements

func (key Key) Elements() []any

Elements returns all elements of the key.

func (Key) Equals added in v0.9.0

func (key Key) Equals(other Key) bool

Equals returns true if the specified key is equal to the key.

func (Key) Len added in v1.0.0

func (key Key) Len() int

Len returns the number of elements of the key.

func (Key) String added in v0.9.0

func (key Key) String() string

String returns a string representation of the key.

type KeyCoder added in v0.9.0

type KeyCoder interface {
	KeyDecoder
	KeyEncoder
}

A KeyCoder includes key decoder and encoder interfaces.

type KeyDecoder added in v0.9.0

type KeyDecoder interface {
	// DecodeKey returns the decoded key from the specified bytes if available, otherwise returns an error.
	DecodeKey([]byte) (Key, error)
}

An KeyDecoder decodes the specified bytes.

type KeyEncoder added in v0.9.0

type KeyEncoder interface {
	// EncodeKey returns the encoded bytes from the specified key if available, otherwise returns an error.
	EncodeKey(Key) ([]byte, error)
}

An KeyEncoder encodes the specified key.

type MapObject added in v1.0.0

type MapObject map[string]any

MapObject represents a map object.

func NewMapObjectFrom added in v1.0.0

func NewMapObjectFrom(anyObj any) (MapObject, error)

NewMapObjectFrom returns a new map object from the specified object.

type Object

type Object = any

Object represents a database object.

type Schema

type Schema interface {
	// Version returns the schema version.
	Version() int
	// SetName sets the specified name to the schema.
	SetName(name string)
	// Name returns the schema name.
	Name() string
	// AddElement adds the specified element to the schema.
	AddElement(elem Element) error
	// DropElement drops the specified element from the schema.
	DropElement(name string) error
	// Elements returns the schema elements.
	Elements() Elements
	// FindElement returns the schema elements by the specified name.
	FindElement(name string) (Element, error)
	// AddIndex adds the specified index to the schema.
	AddIndex(idx Index) error
	// DropIndex drops the specified index from the schema.
	DropIndex(name string) error
	// Indexes returns the schema indexes.
	Indexes() Indexes
	// FindIndex returns the schema index by the spacified name.
	FindIndex(name string) (Index, error)
	// PrimaryIndex returns the schema primary index.
	PrimaryIndex() (Index, error)
	// SecondaryIndexes returns the schema secondary indexes.
	SecondaryIndexes() (Indexes, error)
	// Data returns the raw representation data in memory.
	Data() any
}

Schema represents a schema.

func NewSchema

func NewSchema() Schema

NewSchema returns a blank schema.

func NewSchemaWith

func NewSchemaWith(obj any) (Schema, error)

NewSchemaWith creates a schema from the specified object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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