types

package
v0.0.0-...-b57e8ac Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: Apache-2.0 Imports: 7 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 SAP HANA compatibility layer for MongoDB Wire Protocol:

  1. As they are used in handlers implementation (types package).
  2. As they are used in the wire protocol implementation (bson package).
  3. As they are used to store data in PostgreSQL (fjson package).

The reason for that is a separation of concerns: to avoid method names clashes, to simplify type asserts, etc.

Mapping

Composite/pointer types

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

Scalar/value types

float64          *bson.Double     *fjson.Double
string           *bson.String     *fjson.String
types.Binary     *bson.Binary     *fjson.Binary
types.ObjectID   *bson.ObjectID   *fjson.ObjectID
bool             *bson.Bool       *fjson.Bool
time.Time        *bson.DateTime   *fjson.DateTime
any(nil)         any(nil)         any(nil)
types.Regex      *bson.Regex      *fjson.Regex
int32            *bson.Int32      *fjson.Int32
types.Timestamp  *bson.Timestamp  *fjson.Timestamp
int64            *bson.Int64      *fjson.Int64
TODO Decimal128
types.CString    *bson.CString    *fjson.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

View Source
var Null = NullType{}

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

func MakeArray(capacity int) *Array

MakeArray creates an empty array with set capacity.

func MustNewArray

func MustNewArray(values ...any) *Array

MustNewArray is a NewArray that panics in case of error.

func NewArray

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

NewArray creates an array with the given values.

func (*Array) Append

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

Append appends given values to the array.

func (*Array) Contains

func (a *Array) Contains(key string) bool

func (*Array) Delete

func (a *Array) Delete(index int) (err error)

func (*Array) Get

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

Get returns a value at the given index.

func (*Array) GetByPath

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

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

func (*Array) GetPointer

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

func (*Array) Len

func (a *Array) Len() int

Len returns the number of elements in the array.

func (*Array) Set

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

Set sets the value at the given index.

func (*Array) Subslice

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 CString

type CString string

type CompareResult

type CompareResult int

compareResult represents the result of a comparison.

func CompareScalars

func CompareScalars(a, b any) CompareResult

compareScalars compares two scalar values.

type CompositeType

type CompositeType interface {
	Document | *Array
	GetByPath(path ...string) (any, error)
	// contains filtered or unexported methods
}

CompositeType represents composite/pointer 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 MustMakeDocumentPointer

func MustMakeDocumentPointer(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

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

Get returns a value at the given key.

func (Document) GetByPath

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 document's keys. Do not modify it.

func (Document) Map

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

Map returns this 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 NullType

type NullType struct{}

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