oschema

package
Version: v1.0.0-...-26db8b9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Key schema struct, constructors that are part of the OrientDB schema or support representing the schema.

Index

Constants

View Source
const (
	//
	// Default ClusterID that maps to the "invalid" value on the OrientDB server
	//
	ClusterIDInvalid = -1

	//
	// Default ClusterPos that maps to the "invalid" value on the OrientDB server
	//
	ClusterPosInvalid = -1
)

Variables

This section is empty.

Functions

func ODataTypeNameFor

func ODataTypeNameFor(dt ODataType) string

Types

type OClass

type OClass struct {
	Name             string
	ShortName        string
	Properties       map[string]*OProperty // key=Property.Name
	DefaultClusterID int32                 // TODO: why is this int32 ??  shouldn't it be int16?
	ClusterIDs       []int32               // TODO: why is this int32 ??  shouldn't it be int16?
	SuperClass       string
	OverSize         float32
	StrictMode       bool
	AbstractClass    bool
	ClusterSelection string // OClusterSelectionStrategy in Java code - needed?
	CustomFields     map[string]string
}

func NewOClassFromDocument

func NewOClassFromDocument(doc *ODocument) *OClass

Should be passed an ODocument that comes from a load schema request to the database.

type ODataType

type ODataType byte

ODataType is an enum for the various datatypes supported by OrientDB.

const (
	BOOLEAN      ODataType = 0
	INTEGER      ODataType = 1
	SHORT        ODataType = 2
	LONG         ODataType = 3
	FLOAT        ODataType = 4
	DOUBLE       ODataType = 5
	DATETIME     ODataType = 6
	STRING       ODataType = 7
	BINARY       ODataType = 8 // means []byte
	EMBEDDED     ODataType = 9 // was: EMBEDDEDRECORD
	EMBEDDEDLIST ODataType = 10
	EMBEDDEDSET  ODataType = 11
	EMBEDDEDMAP  ODataType = 12
	LINK         ODataType = 13
	LINKLIST     ODataType = 14
	LINKSET      ODataType = 15
	LINKMAP      ODataType = 16
	BYTE         ODataType = 17
	TRANSIENT    ODataType = 18
	DATE         ODataType = 19
	CUSTOM       ODataType = 20
	DECIMAL      ODataType = 21
	LINKBAG      ODataType = 22
	ANY          ODataType = 23  // BTW: ANY == UNKNOWN/UNSPECIFIED
	UNKNOWN      ODataType = 255 // ogonori addition
)

in alignment with: https://github.com/orientechnologies/orientdb/wiki/Types

type ODocument

type ODocument struct {
	RID     ORID
	Version int32

	Fields map[string]*OField // key: property-name
	// TODO: may want a mapping of ids => OField
	Classname string // TODO: probably needs to change *OClass (once that is built)
	// contains filtered or unexported fields
}

func NewDocument

func NewDocument(className string) *ODocument

NewDocument should be called to create new ODocument objects, since some internal data structures need to be initialized before the ODocument is ready to use.

func NewEmptyDocument

func NewEmptyDocument() *ODocument

TODO: have this replace NewDocument and change NewDocument to take RID and Version (???)

func (*ODocument) AddField

func (doc *ODocument) AddField(name string, field *OField) *ODocument

AddField adds a fully created field directly rather than by some of its attributes, as the other "Field" methods do. The same *ODocument is returned to allow call chaining.

func (*ODocument) ConvertValue

func (doc *ODocument) ConvertValue(v interface{}) (driver.Value, error)

Implements database/sql/driver.ValueConverter interface TODO: haven't detected when this is called yet

func (*ODocument) Field

func (doc *ODocument) Field(name string, val interface{}) *ODocument

Field is used to add a new field to a document. This will usually be done just before calling Save and sending it to the database. The field type will be inferred via type switch analysis on `val`. Use FieldWithType to specify the type directly. The same *ODocument is returned to allow call chaining.

func (*ODocument) FieldNames

func (doc *ODocument) FieldNames() []string

FieldNames returns the names of all the fields currently in this ODocument in "entry order". These fields may not have already been committed to the database.

func (*ODocument) FieldWithType

func (doc *ODocument) FieldWithType(name string, val interface{}, fieldType ODataType) *ODocument

FieldWithType is used to add a new field to a document. This will usually be done just before calling Save and sending it to the database. The `fieldType` must correspond one of the OrientDB type in the schema pkg constants. It will follow the same list as: https://github.com/orientechnologies/orientdb/wiki/Types The same *ODocument is returned to allow call chaining.

func (*ODocument) GetField

func (doc *ODocument) GetField(fname string) *OField

GetFieldByName looks up the OField in this document with the specified field. If no field is found with that name, nil is returned.

func (*ODocument) GetFieldById

func (doc *ODocument) GetFieldById(id int32) *OField

GetFieldById looks up the OField in this document with the specified field id (aka property-id). If no field is found with that id, nil is returned.

func (*ODocument) GetFields

func (doc *ODocument) GetFields() []*OField

GetFields return the OField objects in the Document in "entry order". There is some overhead to getting them in entry order, so if you don't care about that order, just access the Fields field of the ODocument struct directly.

func (*ODocument) Scan

func (doc *ODocument) Scan(src interface{}) error

Implements database/sql.Scanner interface

func (*ODocument) String

func (doc *ODocument) String() string

String implements Stringer interface

func (*ODocument) StringNoFields

func (doc *ODocument) StringNoFields() string

StringNoFields is a String() method that elides the fields. This is useful when the fields include links and there are circular links.

func (*ODocument) ToJSON

func (doc *ODocument) ToJSON() ([]byte, error)

Testing out JSON marshalling -> this method may change to something else

func (*ODocument) Value

func (doc *ODocument) Value() (driver.Value, error)

Implements database/sql/driver.Valuer interface TODO: haven't detected when this is called yet (probably when serializing ODocument for insertion into DB??)

type OEmbeddedArrayMap

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

OEmbeddedArrayMap is optimized for small data sets, since it requires linear searches over the key slice to do lookups. For maps with a small number of entries (< 10 ?) this is typically faster than true hash lookups or tree walks

IMPORTANT NOTE: OEmbeddedArrayMap does not properly handle value changes (keys mapping to new values). They will be appended to the end and the old values will not be removed. TODO: This behavior will be reviewed later.

func (*OEmbeddedArrayMap) All

func (em *OEmbeddedArrayMap) All() (keys []string, vals []interface{}, types []ODataType)

func (*OEmbeddedArrayMap) Get

func (em *OEmbeddedArrayMap) Get(key string) (interface{}, ODataType)

func (*OEmbeddedArrayMap) Keys

func (em *OEmbeddedArrayMap) Keys() []string

func (*OEmbeddedArrayMap) Len

func (em *OEmbeddedArrayMap) Len() int

func (*OEmbeddedArrayMap) Put

func (em *OEmbeddedArrayMap) Put(key string, val interface{}, typ ODataType)

func (OEmbeddedArrayMap) String

func (em OEmbeddedArrayMap) String() string

func (*OEmbeddedArrayMap) Types

func (em *OEmbeddedArrayMap) Types() []ODataType

func (*OEmbeddedArrayMap) Value

func (em *OEmbeddedArrayMap) Value(key string) interface{}

func (*OEmbeddedArrayMap) Values

func (em *OEmbeddedArrayMap) Values() []interface{}

type OEmbeddedList

type OEmbeddedList interface {
	Len() int
	Get(idx int) interface{}
	Add(val interface{})
	// Add(val interface{}, typ ODataType) // TODO: we could allow for mixed type lists -> useful?
	Type() ODataType
	Values() []interface{}
}

OEmbeddedList is a interface wrapper for go slices that should be used when serializing Go ODocuments to the OrientDB database.

func NewEmbeddedSlice

func NewEmbeddedSlice(v []interface{}, typ ODataType) OEmbeddedList

type OEmbeddedMap

type OEmbeddedMap interface {
	Len() int
	Get(key string) (val interface{}, typ ODataType)
	Put(key string, val interface{}, typ ODataType)
	Value(key string) interface{}

	Keys() []string
	Values() []interface{}
	Types() []ODataType
	All() (keys []string, vals []interface{}, types []ODataType)
}

OEmbeddedMap acts like a map[string]interface{} but: * it preserves insertion order * it can optionally retain the data type of the value

Right now there is only an OEmbeddedArrayMap implementation optimized for small maps. If larger maps are needed, an OEmbeddedTreeMap should be implemented.

Note that there is no Delete functionality (will be reviewed for that later)

func NewEmbeddedMap

func NewEmbeddedMap() OEmbeddedMap

Creates an empty EmbeddedMap with default capacity (currently=8)

func NewEmbeddedMapWithCapacity

func NewEmbeddedMapWithCapacity(cap int) OEmbeddedMap

Creates an empty EmbeddedMap with specified capacity

type OEmbeddedSlice

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

func (*OEmbeddedSlice) Add

func (es *OEmbeddedSlice) Add(val interface{})

func (*OEmbeddedSlice) Get

func (es *OEmbeddedSlice) Get(idx int) interface{}

func (*OEmbeddedSlice) Len

func (es *OEmbeddedSlice) Len() int

func (*OEmbeddedSlice) Type

func (es *OEmbeddedSlice) Type() ODataType

func (*OEmbeddedSlice) Values

func (es *OEmbeddedSlice) Values() []interface{}

type OEmbeddedStringList

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

type OField

type OField struct {
	ID    int32 // TODO: is the size specified in OrientDB docs?
	Name  string
	Type  ODataType
	Value interface{}
}

OField is a generic data holder that goes in ODocuments.

func (*OField) String

func (fld *OField) String() string

*OField implements Stringer interface

func (*OField) ToJSON

func (fld *OField) ToJSON() ([]byte, error)

Testing out JSON marshalling -> this method may change to something else

type OGlobalProperty

type OGlobalProperty struct {
	Id   int32
	Name string
	Type ODataType
}

OGlobalProperty is used by OrientDB to efficiently store "property" (field) types and names (but not values) across all clusters in a database These are stored in record #0:1 of a database and loaded when the DBClient starts up. (TODO: it will also need to be updated when new fields are added at runtime)

func NewGlobalPropertyFromDocument

func NewGlobalPropertyFromDocument(doc *ODocument) OGlobalProperty

based on how the Java client does it ; TODO: document usage

type OLink struct {
	RID    ORID       // required
	Record *ODocument // optional
}

OLink represents a LINK in the OrientDB system. It holds a RID and optionally a Record pointer to the ODocument that the RID points to.

func (*OLink) String

func (lnk *OLink) String() string

type OLinkBag

type OLinkBag struct {
	Links []*OLink
	ORemoteLinkBag
}

OLinkBag can have a tree-based or an embedded representation.

Embedded stores its content directly to the document that owns it. It is used when only small numbers of links are stored in the bag.

The tree-based implementation stores its content in a separate data structure called on OSBTreeBonsai on the server. It fits great for cases when you have a large number of links. This is used to efficiently manage relationships (particularly in graph databases).

The OLinkBag struct corresponds to ORidBag in Java client codebase.

func NewOLinkBag

func NewOLinkBag(links []*OLink) *OLinkBag

NewOLinkBag constructor is called with all the OLink objects precreated. Usually appropriate when dealing with an embedded LinkBag.

func NewTreeOLinkBag

func NewTreeOLinkBag(fileID int64, pageIdx int64, pageOffset int32, size int32) *OLinkBag

NewTreeOLinkBag constructor is called for remote tree-based LinkBags. This is called by the Deserializer when all it knows is the pointer reference to the LinkBag on the remote server.

The OLinkBag returned does not yet know the size of the LinkBag nor know what the OLinks are.

func (lb *OLinkBag) AddLink(lnk *OLink)

AddLink adds an *OLink to the slice of *OLink in the OLinkBag

func (*OLinkBag) IsRemote

func (lb *OLinkBag) IsRemote() bool

IsRemote indicates where this LinkBag has its data stored in an opaque format on the remote OrientDB server.

type OProperty

type OProperty struct {
	ID           int32 // TODO: is the size specified in OrientDB docs?
	Name         string
	Fullname     string // Classname.propertyName
	Type         byte   // corresponds to one of the type constants above
	NotNull      bool
	Collate      string // is OCollate in Java client
	Mandatory    bool
	Min          string
	Max          string
	Regexp       string
	CustomFields map[string]string
	Readonly     bool
}

OProperty roughly corresponds to OProperty in the Java client. It represents a property of a class in OrientDB. A property represents the metadata of a field. A field (OField) is the actual data of a field in an ODocument.

func NewOPropertyFromDocument

func NewOPropertyFromDocument(doc *ODocument) *OProperty

NewOPropertyFromDocument creates a new OProperty from an ODocument that was created after a load schema call to the OrientDB server.

type ORID

type ORID struct {
	ClusterID  int16
	ClusterPos int64
}

ORID encapsulates the two aspects of an OrientDB RecordID - ClusterID:ClusterPos

func NewORID

func NewORID() ORID

Returns an ORID with the default "invalid" settings. Invalid settings indicate that the Document has not yet been saved to the DB (which assigns it a valid RID) or it indicates that it is not a true Document with a Class (e.g., it is a result of a Property query)

func NewORIDFromString

func NewORIDFromString(s string) ORID

NewORIDFromString converts a string of form #N:M or N:M to an ORID struct. Make sure to get the string format correctly, as this function panics if any error occurs.

func (ORID) String

func (r ORID) String() string

type ORemoteLinkBag

type ORemoteLinkBag struct {
	CollectionPointer *treeCollectionPointer
	// contains filtered or unexported fields
}

func (*ORemoteLinkBag) GetFileID

func (lb *ORemoteLinkBag) GetFileID() int64

GetFileID returns the fileID of the server collection pointer if the OLinkBag is an instance of ORemoteLinkBag. If the OLinkBAg is not an instance of ORemoteLinkBag, than the return value is meaningless, but no error is returned/thrown in such a case.

func (*ORemoteLinkBag) GetPageIndex

func (lb *ORemoteLinkBag) GetPageIndex() int64

func (*ORemoteLinkBag) GetPageOffset

func (lb *ORemoteLinkBag) GetPageOffset() int32

func (*ORemoteLinkBag) GetRemoteSize

func (lb *ORemoteLinkBag) GetRemoteSize() int

func (*ORemoteLinkBag) SetRemoteSize

func (lb *ORemoteLinkBag) SetRemoteSize(sz int32)

Jump to

Keyboard shortcuts

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