orient

package module
v2.0.0-...-625dcbc Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2018 License: MIT Imports: 17 Imported by: 10

README

Overview

Build Status GoDoc

OrientGo is a Go client for the OrientDB database.

OrientGo Logo

Status

OrientDB versions supported: 2.0.15 - 2.1.5

Not supported versions:

  • 2.1.0 (bug in OrientDB, see #28)
  • 2.1.3 (broken protocol, see #39)

Driver is no longer maintained and seeking for a new owner.

Ogonori

Original ogonori API is deprecated. Still, it's source code have been frozen in v1.0 branch. To use it, simply replace github.com/quux00/ogonori imports with gopkg.in/istreamdata/orientgo.v1.

Supported features:
  • Mostly any SQL queries, commands and batch requests.
  • Server-side scripts (via ScriptCommand or functions).
  • Command results conversion to custom types via mapstructure.
  • Direct CRUD operations on Document or BytesRecord objects.
  • Management of databases and record clusters.
  • Can be used for the golang database/sql API, with some cautions (see below).
  • Only supports OrientDB 2.x series.
Not supported yet:
  • OrientDB 1.x.
  • Servers with cluster configuration (not tested).
  • Fetch plans are temporary disabled due to internal changes.
  • Transactions in Go. Transactions in JS can be used instead.
  • Live queries.
  • Command results streaming (#26).
  • OrientDB CUSTOM type.
  • ORM-like API. See Issue #6.
Caveat on using OrientGo as a database/sql API driver

WARNING: database/sql API is disabled for now.

The golang database/sql API has some constraints that can be make it painful to work with OrientDB. For example:

  • When you insert a record, the Go database/sql API only allows one to return a single int64 identifier for the record, but OrientDB uses as a compound int16:int64 RID, so getting the RID of records you just inserted requires another round trip to the database to query the RID.

Also, since OrientDB transactions are not supported, the Tx portion of the database/sql API is not yet implemented.

Development

You are welcome to initiate pull request and suggest a more user-friendly API. We will try to review them ASAP.

How to run functional tests:

  1. Install Docker

  2. Pull OrientDB image: docker pull dennwc/orientdb:2.1

  3. go test -v ./...

Examples

Dial example - dial_example_test.go

LICENSE

The MIT License

Documentation

Index

Constants

View Source
const (
	// DefaultFetchPlan is an empty fetch plan. Let the database decide. Usually means "do not follow any links".
	DefaultFetchPlan = FetchPlan("")
	// NoFollow is a fetch plan that does not follow any links
	NoFollow = FetchPlan("*:0")
	// FollowAll is a fetch plan that follows all links
	FollowAll = FetchPlan("*:-1")
)
View Source
const (
	LangSQL    = ScriptLang("sql")
	LangJS     = ScriptLang("javascript")
	LangGroovy = ScriptLang("groovy")
)

List of supported server-side script languages

View Source
const (
	ProtoBinary = "binary"
)

Default protocols

Variables

View Source
var ErrNoRecord = fmt.Errorf("no records returned, while expecting one")

ErrNoRecord is returned when trying to deserialize an empty result set into a single value.

View Source
var MaxConnections = 6

MaxConnections limits the number of opened connections.

View Source
var TagName = "mapstructure"

TagName is a name for a struct tag used for types conversion using reflect

Functions

func MarshalContent

func MarshalContent(o interface{}) string

MarshalContent is a helper for constructing SQL commands with CONTENT keyword. Shorthand for json.Marshal. Will panic on errors.

func RegException

func RegException(class string, fnc func(e Exception) Exception)

RegException registers a function to convert server exception based on it's class.

func RegisterMapDecoderHook

func RegisterMapDecoderHook(hook mapstructure.DecodeHookFunc)

RegisterMapDecoderHook allows to register additional hook for map decoder

func RegisterProto

func RegisterProto(name string, dial func(addr string) (DBConnection, error))

RegisterProto registers a new protocol for Dial command

func RegisterRecordFormat

func RegisterRecordFormat(name string, fnc func() RecordSerializer)

RegisterRecordFormat registers RecordSerializer with a given class name

func SerializeAnyStreamable

func SerializeAnyStreamable(o CustomSerializable) ([]byte, error)

SerializeAnyStreamable serializes a given object

func SetDefaultRecordFormat

func SetDefaultRecordFormat(name string)

SetDefaultRecordFormat sets default record serializer

func SetRetryCountConcurrent

func SetRetryCountConcurrent(n int)

SetRetryCountConcurrent sets a retry count when ErrConcurrentModification occurs.

n == 0 - use default value

n < 0 - no limit for retries

n > 0 - maximum of n retries

Types

type Admin

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

Admin wraps a database management session.

func (*Admin) Close

func (a *Admin) Close() error

Close closes DB management session.

func (*Admin) CreateDatabase

func (a *Admin) CreateDatabase(name string, dbType DatabaseType, storageType StorageType) error

CreateDatabase creates a new database with given database type (Document or Graph) and storage type (Persistent or Volatile).

func (*Admin) DatabaseExists

func (a *Admin) DatabaseExists(name string, storageType StorageType) (bool, error)

DatabaseExists checks if database with given name and storage type exists.

func (*Admin) DropDatabase

func (a *Admin) DropDatabase(name string, storageType StorageType) error

DropDatabase removes database from the server.

func (*Admin) ListDatabases

func (a *Admin) ListDatabases() (map[string]string, error)

ListDatabases returns a list of databases in a form:

dbname: dbpath

type BinaryRecordFormat

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

func (BinaryRecordFormat) FromStream

func (f BinaryRecordFormat) FromStream(data []byte) (out ORecord, err error)

func (*BinaryRecordFormat) SetGlobalPropertyFunc

func (f *BinaryRecordFormat) SetGlobalPropertyFunc(fnc GlobalPropertyFunc)

func (BinaryRecordFormat) String

func (BinaryRecordFormat) String() string

func (BinaryRecordFormat) ToStream

func (f BinaryRecordFormat) ToStream(w io.Writer, rec ORecord) error

type BytesRecord

type BytesRecord struct {
	RID  RID
	Vers int
	Data []byte
}

BytesRecord is a rawest representation of a record. It's schema less. Use this if you need to store []byte without matter about the content. Useful also to store multimedia contents and binary files.

func NewBytesRecord

func NewBytesRecord() *BytesRecord

func (BytesRecord) Content

func (r BytesRecord) Content() ([]byte, error)

func (*BytesRecord) Fill

func (r *BytesRecord) Fill(rid RID, version int, content []byte) error

Fill sets identity, version and raw data of the record

func (BytesRecord) GetIdentity

func (r BytesRecord) GetIdentity() RID

GetIdentity returns a record RID

func (BytesRecord) GetRecord

func (r BytesRecord) GetRecord() interface{}

GetRecord returns a record data

func (BytesRecord) RecordType

func (r BytesRecord) RecordType() RecordType

func (*BytesRecord) SetRID

func (r *BytesRecord) SetRID(rid RID)

func (*BytesRecord) SetVersion

func (r *BytesRecord) SetVersion(v int)

func (BytesRecord) String

func (r BytesRecord) String() string

func (BytesRecord) Version

func (r BytesRecord) Version() int

type Classer

type Classer interface {
	// GetClassName return a Java class name for an object
	GetClassName() string
}

Classer is an interface for object that have analogs in OrientDB Java code

type Client

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

Client represents connection to OrientDB server. It is safe for concurrent use.

func Dial

func Dial(addr string) (*Client, error)

Dial opens a new connection to OrientDB server.

For now, user must import protocol implementation, which will be used for connection:

import _  "gopkg.in/istreamdata/orientgo.v2/obinary"

Address must be in host:port format. Connection to OrientDB cluster is not supported yet.

Returned Client uses connection pool under the hood, so it can be shared between goroutines.

func (*Client) Auth

func (c *Client) Auth(user, pass string) (*Admin, error)

Auth initiates a new administration session with OrientDB server, allowing to manage databases.

func (*Client) Close

func (c *Client) Close() error

Close must be called to close all active DB connections.

func (*Client) Open

func (c *Client) Open(name string, dbType DatabaseType, user, pass string) (*Database, error)

Open initiates a new database session, allowing to make queries to selected database.

For database management use Auth instead.

type CustomSerializable

type CustomSerializable interface {
	Classer
	Serializable
}

CustomSerializable is an interface for objects that can be sent on wire

type DBAdmin

type DBAdmin interface {
	DatabaseExists(name string, storageType StorageType) (bool, error)
	CreateDatabase(name string, dbType DatabaseType, storageType StorageType) error
	DropDatabase(name string, storageType StorageType) error
	ListDatabases() (map[string]string, error)
	Close() error
}

DBAdmin is a minimal interface for database management API implementation

type DBConnection

type DBConnection interface {
	Auth(user, pass string) (DBAdmin, error)
	Open(name string, dbType DatabaseType, user, pass string) (DBSession, error)
	Close() error
}

DBConnection is a minimal interface for OrientDB server API implementation

type DBSession

type DBSession interface {
	Close() error
	Size() (int64, error)
	ReloadSchema() error
	GetCurDB() *ODatabase

	AddClusterWithID(clusterName string, id int16) (clusterID int16, err error)
	DropCluster(clusterName string) (err error)
	GetClusterDataRange(clusterName string) (begin, end int64, err error)
	ClustersCount(withDeleted bool, clusterNames ...string) (int64, error)

	CreateRecord(rec ORecord) (err error)
	DeleteRecordByRID(rid RID, recVersion int) error
	GetRecordByRID(rid RID, fetchPlan FetchPlan, ignoreCache bool) (rec ORecord, err error)
	UpdateRecord(rec ORecord) error
	CountRecords() (int64, error)

	Command(cmd CustomSerializable) (result interface{}, err error)
}

DBSession is a minimal interface for database API implementation

type Database

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

Database wraps a database session. It is safe for concurrent use.

func (*Database) AddCluster

func (db *Database) AddCluster(name string) (int16, error)

AddCluster creates new cluster with given name and returns its ID.

func (*Database) AddClusterWithID

func (db *Database) AddClusterWithID(name string, clusterID int16) (int16, error)

AddClusterWithID creates new cluster with given cluster position and name

func (*Database) CallScriptFunc

func (db *Database) CallScriptFunc(name string, params ...interface{}) Results

CallScriptFunc is a helper for calling server-side functions (especially JS). Ideally should be a shorthand for

db.Command(NewFunctionCommand(name, params...))

but it uses some workarounds to allow to return JS objects from that functions.

func (*Database) Close

func (db *Database) Close() error

Close closes database session.

func (*Database) ClustersCount

func (db *Database) ClustersCount(withDeleted bool, clusterNames ...string) (int64, error)

ClustersCount returns total count of records in given clusters

func (*Database) Command

func (db *Database) Command(cmd OCommandRequestText) Results

Command executes command against current database. Example:

result := db.Command(NewSQLQuery("SELECT FROM V WHERE id = ?", id).Limit(10))

func (*Database) CountRecords

func (db *Database) CountRecords() (int64, error)

CountRecords returns total records count.

func (*Database) CreateRecord

func (db *Database) CreateRecord(rec ORecord) error

CreateRecord saves a record to the database. Record RID and version will be changed.

func (*Database) CreateScriptFunc

func (db *Database) CreateScriptFunc(fnc Function) error

CreateScriptFunc is a helper for saving server-side functions to database.

func (*Database) DeleteRecordByRID

func (db *Database) DeleteRecordByRID(rid RID, recVersion int) error

DeleteRecordByRID removes a record from database

func (*Database) DeleteScriptFunc

func (db *Database) DeleteScriptFunc(name string) error

DeleteScriptFunc deletes server-side function with a given name from current database.

func (*Database) DropCluster

func (db *Database) DropCluster(name string) error

DropCluster deletes cluster from database

func (*Database) GetClusterDataRange

func (db *Database) GetClusterDataRange(clusterName string) (begin, end int64, err error)

GetClusterDataRange returns the begin and end positions of data in the requested cluster.

func (*Database) GetCurDB

func (db *Database) GetCurDB() *ODatabase

GetCurDB returns database metadata

func (*Database) GetRecordByRID

func (db *Database) GetRecordByRID(rid RID, fetchPlan FetchPlan, ignoreCache bool) (ORecord, error)

GetRecordByRID returns a record using specified fetch plan. If ignoreCache is set to true implementations will not use local records cache and will fetch record from database.

func (*Database) InitScriptFunc

func (db *Database) InitScriptFunc(fncs ...Function) (err error)

InitScriptFunc is a helper for updating all server-side functions to specified state.

func (*Database) ReloadSchema

func (db *Database) ReloadSchema() error

ReloadSchema reloads documents schema from database.

func (*Database) Size

func (db *Database) Size() (int64, error)

Size return the size of current database (in bytes).

func (*Database) UpdateRecord

func (db *Database) UpdateRecord(rec ORecord) error

UpdateRecord updates given record in a database. Record version will be changed after the call.

func (*Database) UpdateScriptFunc

func (db *Database) UpdateScriptFunc(name string, script string) error

UpdateScriptFunc updates code of server-side function

type DatabaseType

type DatabaseType string

DatabaseType defines database access type (Document or Graph)

const (
	DocumentDB DatabaseType = "document"
	GraphDB    DatabaseType = "graph"
)

List of database access types

type Decimal

type Decimal struct {
	Scale int
	Value *big.Int
}

type Deserializable

type Deserializable interface {
	FromStream(r io.Reader) error
}

Deserializable is an interface for objects that can be deserialized from stream

type DocEntry

type DocEntry struct {
	Name  string
	Type  OType
	Value interface{}
}

DocEntry is a generic data holder that goes in Documents.

func (*DocEntry) String

func (fld *DocEntry) String() string

type Document

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

func NewDocument

func NewDocument(className string) *Document

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

func NewDocumentFromRID

func NewDocumentFromRID(rid RID) *Document

NewDocumentFromRID creates new empty document with given RID.

func NewEmptyDocument

func NewEmptyDocument() *Document

NewEmptyDocument creates new empty document.

func (*Document) AddField

func (doc *Document) AddField(name string, field *DocEntry) *Document

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

func (*Document) ClassName

func (doc *Document) ClassName() string

func (*Document) Content

func (doc *Document) Content() ([]byte, error)

func (*Document) FieldNames

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

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

func (*Document) Fields

func (doc *Document) Fields() map[string]*DocEntry

func (*Document) FieldsArray

func (doc *Document) FieldsArray() []*DocEntry

FieldsArray 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 Document struct directly.

func (*Document) Fill

func (doc *Document) Fill(rid RID, version int, content []byte) error

func (*Document) FillClassNameIfNeeded

func (doc *Document) FillClassNameIfNeeded(name string)

func (*Document) From

func (doc *Document) From(o interface{}) error

From sets Document fields to values provided in argument (which can be a map or a struct).

From uses TagName field tag to determine field name and conversion parameters. For now it supports only one special tag parameter: ",squash" which can be used to inline fields into parent struct.

func (*Document) GetField

func (doc *Document) GetField(fname string) *DocEntry

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

func (*Document) GetIdentity

func (doc *Document) GetIdentity() RID

func (*Document) GetRecord

func (doc *Document) GetRecord() interface{}

func (*Document) RawContainsField

func (doc *Document) RawContainsField(name string) bool

func (*Document) RawSetField

func (doc *Document) RawSetField(name string, val interface{}, fieldType OType)

func (*Document) RecordType

func (doc *Document) RecordType() RecordType

func (*Document) SetClassNameIfExists

func (doc *Document) SetClassNameIfExists(name string)

func (*Document) SetDirty

func (doc *Document) SetDirty(b bool)

func (*Document) SetField

func (doc *Document) SetField(name string, val interface{}) *Document

SetField 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 *Document is returned to allow call chaining.

func (*Document) SetFieldWithType

func (doc *Document) SetFieldWithType(name string, val interface{}, fieldType OType) *Document

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 *Document is returned to allow call chaining.

func (*Document) SetSerializer

func (doc *Document) SetSerializer(ser RecordSerializer)

SetSerializer sets RecordSerializer for encoding/decoding a Document

func (*Document) String

func (doc *Document) String() string

func (*Document) ToDocument

func (doc *Document) ToDocument() (*Document, error)

ToDocument implement DocumentSerializable interface. In this case, Document just returns itself.

func (*Document) ToMap

func (doc *Document) ToMap() (map[string]interface{}, error)

func (*Document) ToStruct

func (doc *Document) ToStruct(o interface{}) error

ToStruct fills provided struct with content of a Document. Argument must be a pointer to structure.

type DocumentDeserializable

type DocumentDeserializable interface {
	FromDocument(*Document) error
}

DocumentDeserializable is an interface for objects that can be filled from Document

type DocumentSerializable

type DocumentSerializable interface {
	ToDocument() (*Document, error)
}

DocumentSerializable is an interface for objects that can be converted to Document

type ErrConcurrentModification

type ErrConcurrentModification struct {
	Exception
}

func (ErrConcurrentModification) Error

type ErrInvalidConn

type ErrInvalidConn struct {
	Msg string
}

ErrInvalidConn is returned than DB functions are called without active DB connection

func (ErrInvalidConn) Error

func (e ErrInvalidConn) Error() string

type ErrMultipleRecords

type ErrMultipleRecords struct {
	N   int
	Err error
}

ErrMultipleRecords is returned when trying to deserialize a result set with multiple records into a single value.

func (ErrMultipleRecords) Error

func (e ErrMultipleRecords) Error() string

type ErrTypeSerialization

type ErrTypeSerialization struct {
	Val        interface{}
	Serializer interface{}
}

ErrTypeSerialization represent serialization/deserialization error

func (ErrTypeSerialization) Error

func (e ErrTypeSerialization) Error() string

type ErrUnsupportedConversion

type ErrUnsupportedConversion struct {
	From reflect.Value
	To   reflect.Value
}

func (ErrUnsupportedConversion) Error

func (e ErrUnsupportedConversion) Error() string

type Exception

type Exception interface {
	error
	// Returns Java exception class
	ExcClass() string
	// Returns exception message
	ExcMessage() string
}

Exception is an interface for Java-based Exceptions.

type FetchPlan

type FetchPlan string

FetchPlan is an additional parameter to queries, that instructs DB how to handle linked documents.

The format is:

(field:depth)*

Field is the name of the field to specify the depth-level. Wildcard '*' means any fields.

Depth is the depth level to fetch. -1 means infinite, 0 means no fetch at all and 1-N the depth level value.

WARN: currently fetch plan have no effect on returned results, as records cache is not implemented yet.

type Function

type Function struct {
	Name   string
	Lang   ScriptLang
	Params []string
	Idemp  bool // is idempotent
	Code   string
}

Function is a server-side function description

type FunctionCommand

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

FunctionCommand is a command to call server-side function.

OCommandFunction in Java world.

func NewFunctionCommand

func NewFunctionCommand(name string, params ...interface{}) FunctionCommand

NewFunctionCommand creates a new call request to server-side function with given name and arguments.

func (FunctionCommand) GetClassName

func (rq FunctionCommand) GetClassName() string

GetClassName returns Java class name

func (FunctionCommand) GetText

func (rq FunctionCommand) GetText() string

func (FunctionCommand) ToStream

func (rq FunctionCommand) ToStream(w io.Writer) error

type GlobalPropertyFunc

type GlobalPropertyFunc func(id int) (OGlobalProperty, bool)

GlobalPropertyFunc is a function for getting global properties by id

type MapSerializable

type MapSerializable interface {
	ToMap() (map[string]interface{}, error)
}

MapSerializable is an interface for objects that can be converted to map[string]interface{}

type OClass

type OClass struct {
	Name             string
	ShortName        string
	Properties       map[string]*OProperty
	DefaultClusterId int32
	ClusterIds       []int32
	SuperClass       string
	OverSize         float32
	StrictMode       bool
	AbstractClass    bool
	ClusterSelection string // OClusterSelectionStrategy in Java code - needed?
	CustomFields     map[string]string
}

func NewOClassFromDocument

func NewOClassFromDocument(doc *Document) *OClass

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

type OCommandRequestText

type OCommandRequestText interface {
	CustomSerializable
	GetText() string
}

OCommandRequestText is an interface for text-based database commands, which can be executed using database.Command function.

type ODatabase

type ODatabase struct {
	Name    string
	Type    DatabaseType
	Classes map[string]*OClass
}

ODatabase stores database metadata

type OGlobalProperty

type OGlobalProperty struct {
	Id   int32 // TODO: change to int?
	Name string
	Type OType
}

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 *Document) OGlobalProperty

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

type OIdentifiable

type OIdentifiable interface {
	GetIdentity() RID
	GetRecord() interface{}
}

type OIdentifiableCollection

type OIdentifiableCollection interface {
	Len() int
	OIdentifiableIterator() <-chan OIdentifiable
}

type OProperty

type OProperty struct {
	Id           int32
	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 Document.

func NewOPropertyFromDocument

func NewOPropertyFromDocument(doc *Document) *OProperty

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

type ORecord

type ORecord interface {
	OIdentifiable
	Fill(rid RID, version int, content []byte) error // TODO: put to separate interface?
	Content() ([]byte, error)
	Version() int
	SetVersion(v int)
	SetRID(rid RID)
	RecordType() RecordType
}

func NewRecordOfType

func NewRecordOfType(tp RecordType) ORecord

NewRecordOfType creates a new record of specified type

type OServerException

type OServerException struct {
	Exceptions []Exception
}

OServerException encapsulates Java-based Exceptions from the OrientDB server. OrientDB can return multiple exceptions for a single query/command, so they are all encapsulated in one OServerException object.

func (OServerException) Error

func (e OServerException) Error() string

type OType

type OType byte

OType is an enum for the various data types supported by OrientDB.

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

in alignment with: http://orientdb.com/docs/last/Types.html

func OTypeForValue

func OTypeForValue(val interface{}) (ftype OType)

func OTypeFromString

func OTypeFromString(typ string) OType

func (OType) ReflectKind

func (t OType) ReflectKind() reflect.Kind

func (OType) ReflectType

func (t OType) ReflectType() reflect.Type

func (OType) String

func (t OType) String() string

type RID

type RID struct {
	ClusterID  int16
	ClusterPos int64
}

RID encapsulates the two aspects of an OrientDB RecordID - ClusterID:ClusterPos. ORecordId in Java world.

func MustParseRID

func MustParseRID(s string) RID

MustParseRID is a version of ParseRID which panics on errors

func NewEmptyRID

func NewEmptyRID() RID

NewEmptyRID returns an RID 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 NewRID

func NewRID(cid int16, pos int64) RID

NewRID creates a RID with given ClusterId and ClusterPos. It will check value for validity.

func NewRIDInCluster

func NewRIDInCluster(cid int16) RID

NewRIDInCluster creates an empty RID inside specified cluster

func ParseRID

func ParseRID(s string) (RID, error)

ParseRID converts a string of form #N:M or N:M to a RID.

func (*RID) FromStream

func (rid *RID) FromStream(r io.Reader) error

func (RID) GetIdentity

func (r RID) GetIdentity() RID

GetIdentity implements OIdentifiable interface on RID

func (RID) GetRecord

func (r RID) GetRecord() interface{}

func (RID) IsNew

func (rid RID) IsNew() bool

func (RID) IsPersistent

func (rid RID) IsPersistent() bool

func (RID) IsTemporary

func (rid RID) IsTemporary() bool

func (RID) IsValid

func (r RID) IsValid() bool

func (RID) Next

func (rid RID) Next() string

Next is a shortcut for rid.NextRID().String()

func (RID) NextRID

func (rid RID) NextRID() RID

NextRID returns next RID in current cluster

func (RID) String

func (rid RID) String() string

String converts RID to #N:M string format

func (RID) ToStream

func (rid RID) ToStream(w io.Writer) error

type RecordFactory

type RecordFactory func() ORecord

RecordFactory is a function to create records of certain type

func GetRecordFactory

func GetRecordFactory(tp RecordType) RecordFactory

GetRecordFactory returns RecordFactory for a given type

type RecordSerializer

type RecordSerializer interface {
	// String, in case of RecordSerializer must return it's class name, as it will be sent to server
	String() string

	ToStream(w io.Writer, rec ORecord) error
	FromStream(data []byte) (ORecord, error)

	SetGlobalPropertyFunc(fnc GlobalPropertyFunc)
}

RecordSerializer is an interface for serializing records to byte streams

func GetDefaultRecordSerializer

func GetDefaultRecordSerializer() RecordSerializer

GetDefaultRecordSerializer returns default record serializer

func GetRecordFormat

func GetRecordFormat(name string) RecordSerializer

GetRecordFormat returns record serializer by class name

type RecordType

type RecordType byte

RecordType defines a registered record type

const (
	RecordTypeDocument RecordType = 'd'
	RecordTypeBytes    RecordType = 'b'
	RecordTypeFlat     RecordType = 'f'
)

List of standard record types

type Results

type Results interface {
	Err() error
	Close() error
	Next(result interface{}) bool
	All(result interface{}) error
}

Results is an interface for database command results. Must be closed.

Individual results can be iterated in a next way:

results := db.Command(cmd)
if err := results.Err(); err != nil {
	// handle command errors; can be omitted and checked later with Err or Close
}
var one SomeStruct
for results.Next(&one) {
	// process result, if any
}
if err := results.Close(); err != nil {
	// handle command and/or type conversion errors
}

Or just retrieved all at once:

var arr []SomeStruct
if err := results.All(&arr); err != nil {
	// handle command and/or type conversion errors
}

Some commands may return just one int/bool value:

var affected int
results.All(&affected)

Also results can be handled manually:

var out interface{}
results.All(&out)
switch out.(type) {
case []OIdentifiable:
	// ...
case *DocumentRecord:
	// ...
}

type RidBag

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

RidBag 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 RidBag struct corresponds to ORidBag in Java client codebase.

func NewRidBag

func NewRidBag() *RidBag

func (*RidBag) FromStream

func (bag *RidBag) FromStream(r io.Reader) error

func (*RidBag) IsRemote

func (bag *RidBag) IsRemote() bool

func (*RidBag) SetOwner

func (bag *RidBag) SetOwner(doc *Document)

func (*RidBag) ToStream

func (bag *RidBag) ToStream(w io.Writer) error

type SQLCommand

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

SQLCommand is a non-SELECT sql command (EXEC/INSERT/DELETE).

OCommandSQL in Java world.

func NewSQLCommand

func NewSQLCommand(sql string, params ...interface{}) SQLCommand

NewSQLCommand creates a new SQL command request with given params.

Example:

NewSQLCommand("INSERT INTO People (id, name) VALUES (?, ?)", id, name)

func (SQLCommand) GetClassName

func (rq SQLCommand) GetClassName() string

GetClassName returns Java class name

func (SQLCommand) GetText

func (rq SQLCommand) GetText() string

func (SQLCommand) ToStream

func (rq SQLCommand) ToStream(w io.Writer) error

type SQLQuery

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

SQLQuery is a SELECT-like SQL command.

OSQLQuery in Java world.

func NewSQLQuery

func NewSQLQuery(sql string, params ...interface{}) SQLQuery

NewSQLQuery creates a new SQL query with given params.

Example:

NewSQLQuery("SELECT FROM V WHERE id = ?", id)

func (SQLQuery) FetchPlan

func (rq SQLQuery) FetchPlan(plan FetchPlan) SQLQuery

FetchPlan sets a query fetch plan

func (SQLQuery) GetClassName

func (rq SQLQuery) GetClassName() string

GetClassName returns Java class name

func (SQLQuery) GetText

func (rq SQLQuery) GetText() string

GetText returns query text

func (SQLQuery) Limit

func (rq SQLQuery) Limit(n int) SQLQuery

Limit sets a query record limit

func (SQLQuery) ToStream

func (rq SQLQuery) ToStream(w io.Writer) error

ToStream serializes command to specified Writer

type ScriptCommand

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

ScriptCommand is a way to execute batch-like commands.

OCommandScript in Java world.

func NewScriptCommand

func NewScriptCommand(lang ScriptLang, body string, params ...interface{}) ScriptCommand

NewScriptCommand creates a new script request written in a given language (SQL/JS/Groovy/...), with specified body code and params.

Example:

NewScriptCommand(LangJS, `var out = db.command("SELECT FROM V"); out`)

func (ScriptCommand) GetClassName

func (rq ScriptCommand) GetClassName() string

GetClassName returns Java class name

func (ScriptCommand) GetText

func (rq ScriptCommand) GetText() string

func (ScriptCommand) ToStream

func (rq ScriptCommand) ToStream(w io.Writer) error

ToStream serializes command to specified Writer

type ScriptLang

type ScriptLang string

ScriptLang is a type for supported server-side script languages

type Serializable

type Serializable interface {
	ToStream(w io.Writer) error
}

Serializable is an interface for objects that can be serialized to stream

type StorageType

type StorageType string

StorageType defines supported database storage types

const (
	// Persistent type represents on-disk database
	Persistent StorageType = "plocal"
	// Volatile type represents in-memory database
	Volatile StorageType = "memory"
)

type StringRecordFormatAbs

type StringRecordFormatAbs struct{}

func (StringRecordFormatAbs) FieldTypeFromStream

func (f StringRecordFormatAbs) FieldTypeFromStream(tp OType, s string) interface{}

func (StringRecordFormatAbs) GetType

func (StringRecordFormatAbs) GetType(s string) OType

type UnknownException

type UnknownException struct {
	Class   string
	Message string
}

UnknownException is an arbitrary exception from Java side. If exception class is not recognized by this driver, it will return UnknownException.

func (UnknownException) Error

func (e UnknownException) Error() string

func (UnknownException) ExcClass

func (e UnknownException) ExcClass() string

ExcClass returns Java exception class

func (UnknownException) ExcMessage

func (e UnknownException) ExcMessage() string

ExcMessage returns exception message

Directories

Path Synopsis
rw
rw is the read-write package for reading and writing types from the OrientDB binary network protocol.
rw is the read-write package for reading and writing types from the OrientDB binary network protocol.

Jump to

Keyboard shortcuts

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