types

package
v0.0.5 Latest Latest
Warning

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

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

Documentation

Overview

Package types provides Go types matching BSON types without built-in Go equivalents.

All BSON data types have three representations in FerretDB:

  1. As they are used in handlers implementation.
  2. As they are used in the wire protocol implementation.
  3. As they are used to store data in PostgreSQL.

The first representation is provided by this package (types). The second and third representations are provided by the bson package. The reason for that is a separation of concerns: to avoid method names clashes, to simplify type asserts, etc.

Mapping

Composite types

types.Document    bson.Document
*types.Array      bson.Array

Value types

float64           bson.Double
string            bson.String
types.Binary      bson.Binary
types.ObjectID    bson.ObjectID
bool              bson.Bool
time.Time         bson.DateTime
any(nil)          any(nil)
types.Regex       bson.Regex
int32             bson.Int32
types.Timestamp   bson.Timestamp
int64             bson.Int64
TODO              bson.Decimal128
(does not exist)  bson.CString

Index

Constants

View Source
const (
	BinaryGeneric    = BinarySubtype(0x00) // generic
	BinaryFunction   = BinarySubtype(0x01) // function
	BinaryGenericOld = BinarySubtype(0x02) // generic-old
	BinaryUUIDOld    = BinarySubtype(0x03) // uuid-old
	BinaryUUID       = BinarySubtype(0x04) // uuid
	BinaryMD5        = BinarySubtype(0x05) // md5
	BinaryEncrypted  = BinarySubtype(0x06) // encrypted
	BinaryUser       = BinarySubtype(0x80) // user
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array represents BSON array.

Zero value is a valid empty array.

func MakeArray added in v0.0.5

func MakeArray(capacity int) *Array

MakeArray creates an empty array with set capacity.

func MustNewArray added in v0.0.5

func MustNewArray(values ...any) *Array

MustNewArray is a NewArray that panics in case of error.

func NewArray added in v0.0.5

func NewArray(values ...any) (*Array, error)

NewArray creates an array with the given values.

func (*Array) Append added in v0.0.5

func (a *Array) Append(values ...any) error

Append appends given values to the array.

func (*Array) Get added in v0.0.5

func (a *Array) Get(index int) (any, error)

Get returns a value at the given index.

func (*Array) GetByPath added in v0.0.5

func (a *Array) GetByPath(path ...string) (any, error)

GetByPath returns a value by path - a sequence of indexes and keys.

func (*Array) Len added in v0.0.5

func (a *Array) Len() int

Len returns the number of elements in the array.

func (*Array) Set added in v0.0.5

func (a *Array) Set(index int, value any) error

Set sets the value at the given index.

func (*Array) Subslice added in v0.0.5

func (a *Array) Subslice(low, high int) (*Array, error)

Subslice returns a slice of the array, sharing the same underlying space and elements.

type Binary

type Binary struct {
	Subtype BinarySubtype
	B       []byte
}

type BinarySubtype

type BinarySubtype byte

func (BinarySubtype) String

func (i BinarySubtype) String() string

type CompositeType added in v0.0.5

type CompositeType interface {
	// contains filtered or unexported methods
}

CompositeType represents composite type - Document or *Array.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document represents BSON document.

Duplicate field names are not supported.

func ConvertDocument

func ConvertDocument(d document) (Document, error)

ConvertDocument converts bson.Document to types.Document and validates it. It references the same data without copying it.

func MakeDocument

func MakeDocument(pairs ...any) (Document, error)

MakeDocument makes a new Document from given key/value pairs.

func MustConvertDocument

func MustConvertDocument(d document) Document

MustConvertDocument is a ConvertDocument that panics in case of error.

func MustMakeDocument

func MustMakeDocument(pairs ...any) Document

MustMakeDocument is a MakeDocument that panics in case of error.

func (Document) Command

func (d Document) Command() string

Command returns the first document's key, this is often used as a command name.

func (Document) Get added in v0.0.5

func (d Document) Get(key string) (any, error)

Get returns a value at the given key.

func (Document) GetByPath added in v0.0.5

func (d Document) GetByPath(path ...string) (any, error)

GetByPath returns a value by path - a sequence of indexes and keys.

func (Document) Keys

func (d Document) Keys() []string

Keys returns a shallow copy of the document's keys. Do not modify it.

func (Document) Map

func (d Document) Map() map[string]any

Map returns a shallow copy of the document as a map. Do not modify it.

func (*Document) Remove

func (d *Document) Remove(key string)

Remove the given key, doing nothing if the key does not exist.

func (*Document) Set

func (d *Document) Set(key string, value any) error

Set the value of the given key, replacing any existing value.

type ObjectID

type ObjectID [12]byte

type Regex

type Regex struct {
	Pattern string
	Options string
}

type Timestamp

type Timestamp uint64

Jump to

Keyboard shortcuts

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