Documentation
¶
Overview ¶
Package types provides Go types matching BSON types without built-in Go equivalents.
All BSON data types have three representations in FerretDB:
- As they are used in handlers implementation.
- As they are used in the wire protocol implementation.
- 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
- type Array
- type Binary
- type BinarySubtype
- type CompositeType
- type Document
- func (d Document) Command() string
- func (d Document) Get(key string) (any, error)
- func (d Document) GetByPath(path ...string) (any, error)
- func (d Document) Keys() []string
- func (d Document) Map() map[string]any
- func (d *Document) Remove(key string)
- func (d *Document) Set(key string, value any) error
- type ObjectID
- type Regex
- type Timestamp
Constants ¶
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 MustNewArray ¶ added in v0.0.5
MustNewArray is a NewArray that panics in case of error.
func (*Array) GetByPath ¶ added in v0.0.5
GetByPath returns a value by path - a sequence of indexes and keys.
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 ¶
ConvertDocument converts bson.Document to types.Document and validates it. It references the same data without copying it.
func MakeDocument ¶
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 ¶
MustMakeDocument is a MakeDocument that panics in case of error.
func (Document) Command ¶
Command returns the first document's key, this is often used as a command name.
func (Document) GetByPath ¶ added in v0.0.5
GetByPath returns a value by path - a sequence of indexes and keys.