Module odi

Low level interface to access OrientDB.

See also: odi_graph, if you want higher level access for graphs.

Description

Low level interface to access OrientDB

Data Types

collection_change()

collection_change() = {Uuid::integer(), UpdatedFileId::integer(), UpdatePageIndex::integer(), UpdatedPageOffset::integer()}

error()

error() = {error, [{ExceptionClass::binary(), ExceptionMessage::binary()}]}

Result type for an error

fetched_record()

fetched_record() = {Key::true | rid(), document, Version::integer(), Class::string(), Data::#{}} | {Key::true | rid(), raw, Version::integer(), Class::raw, Data::binary()}

The result of a record fetch

mode()

mode() = sync | async | no_response

record()

record() = {Class::string(), Data::#{string() => any()}}

record_type()

record_type() = raw | flat | document

rid()

rid() = {ClusterId::integer(), ClusterPosition::integer()}

A record ID

tx_operation()

tx_operation() = {update, Rid::rid(), RecordType::record_type(), Version::integer(), UpdateContent::boolean(), Record::record()} | {delete, Rid::rid(), RecordType::record_type(), Version::integer()} | {create, Rid::rid(), RecordType::record_type(), Record::record()}

A transaction operation

Function Index

close/1Close the connection.
command/2Synchronous SQL command.
command/4Synchronous SQL command with parameters.
connect/4Connect to a server.
datacluster_add/3Add a new data cluster.
datacluster_remove/2Remove a cluster.
db_close/1Closes the database and the network connection to the OrientDB Server instance.
db_countrecords/1Asks for the number of records in a database in the OrientDB Server instance.
db_create/5Creates a database in the remote OrientDB server instance.
db_delete/3Removes a database from the OrientDB Server instance.
db_exist/3Asks if a database exists in the OrientDB Server instance.
db_open/5Open a database.
db_reload/1Reloads database information.
db_size/1Returns size of the opened database.
live_query/3Live SELECT query.
live_query/4Live SELECT query with parameters.
query/4SQL query (SELECT or TRAVERSE).
query/5SQL query with parameters (SELECT or TRAVERSE).
record_create/5Create a new record.
record_delete/4Delete a record by its RecordID.
record_load/4Load a record by RecordID, according to a fetch plan.
record_update/6Update a record.
record_update/7Update a record.
script/3Synchronous script.
script/5Synchronous script with parameters.
tx_commit/4Commits a transaction.

Function Details

close/1

close(C::pid()) -> ok

Close the connection.

command/2

command(C::pid(), SQL::string()) -> [fetched_record()] | error()

Synchronous SQL command.

[{Rid, document, 1, "Test", Data}] = odi:command(Con2, "INSERT INTO Test (x) VALUES (X')").'

command/4

command(C::pid(), SQL::string(), SimpleParams::#{string() => any()} | null, ComplexParams::#{string() => {embedded_list, []}} | null) -> [fetched_record()] | error()

Synchronous SQL command with parameters.

  [{Rid, document, 1, "Test", Data}] =
      odi:command(Con2, "INSERT INTO Test (x) VALUES (:x)", #{"x" => "X"}).

connect/4

connect(Host::string(), Username::string(), Password::string(), Opts::[{timeout, Timeout::integer()} | {port, Port::integer()}]) -> {ok, Con::pid()} | error()

Connect to a server.

This is the first operation requested by the client when it needs to work with the server instance without opening a database.

{ok, Con} = odi:connect("127.0.0.1", "server_user", "server_password", []).

datacluster_add/3

datacluster_add(C::pid(), Name::string(), ClusterId::integer()) -> integer() | error()

Add a new data cluster.

If you pass -1 as ClusterId, the server will assign one.

NewClusterId = odi:datacluster_add(Con, "toto", -1).

datacluster_remove/2

datacluster_remove(C::pid(), ClusterId::integer()) -> boolean() | error()

Remove a cluster.

db_close/1

db_close(C::pid()) -> {stop, closed}

Closes the database and the network connection to the OrientDB Server instance.

db_countrecords/1

db_countrecords(C::pid()) -> integer() | error()

Asks for the number of records in a database in the OrientDB Server instance.

db_create/5

db_create(C::pid(), DatabaseName::string(), DatabaseType::string(), StorageType::string(), BackupPath::string()) -> ok | error()

Creates a database in the remote OrientDB server instance.

Works in connect-mode.

ok = db_create(Con, "test", "graph", "plocal", null).

db_delete/3

db_delete(C::pid(), DatabaseName::string(), StorageType::string()) -> ok | error()

Removes a database from the OrientDB Server instance.

Works in connect-mode.

db_delete(Con, "test", "plocal").

db_exist/3

db_exist(C::pid(), DatabaseName::string(), StorageType::string()) -> boolean() | error()

Asks if a database exists in the OrientDB Server instance.

It returns true (non-zero) or false (zero). Works in connect-mode.

db_exist(Con, "test", "plocal").

db_open/5

db_open(Host::string(), Dbname::string(), Username::string(), Password::string(), Opts::[{timeout, Timeout::integer()} | {port, Port::integer()}]) -> {Clusters::[{ClusterName::string(), ClusterId::integer()}], Con::pid()} | error()

Open a database

This is the first operation the client should call. It opens a database on the remote OrientDB Server.

{Clusters, Con} = odi:db_open("127.0.0.1", "demo", "admin", "admin", []).

db_reload/1

db_reload(C::pid()) -> [{ClusterName::string(), ClusterId::integer()}] | error()

Reloads database information.

db_size/1

db_size(C::pid()) -> integer() | error()

Returns size of the opened database.

live_query/3

live_query(C::pid(), SQL::string(), CallBack::fun((live | live_unsubscription, {loaded | updated | deleted | created, fetched_record()} | {}) -> any())) -> {ok, Token::integer()} | error()

Live SELECT query.

  TestPid = self(),
  {ok, Token} = odi:live_query(Con, "LIVE SELECT FROM Test", fun(What, Message) ->
      TestPid ! {What, Message}
  end).

live_query/4

live_query(C::pid(), SQL::string(), Params::#{string() => any()} | null, CallBack::fun((live, {loaded | updated | deleted | created, fetched_record()}) -> any())) -> {ok, Token::integer()} | error()

Live SELECT query with parameters.

See also: live_query/3.

query/4

query(C::pid(), SQL::string(), Limit::integer(), FetchPlan::string() | default) -> {Results::[fetched_record()], Cached::[fetched_record()]} | error()

SQL query (SELECT or TRAVERSE).

{ResultsReadBack, ResultsReadBackCache} = odi:query(Con, "select from V", -1, default).

query/5

query(C::pid(), SQL::string(), Limit::integer(), FetchPlan::string() | default, Params::#{string() => any()} | null) -> {Results::[fetched_record()], Cached::[fetched_record()]} | error()

SQL query with parameters (SELECT or TRAVERSE).

  {ResultsReadBack, ResultsReadBackCache} =
      odi:query(Con, "select from V where x=:value", -1, default, #{"value" => 42}).

record_create/5

record_create(C::pid(), ClusterId::integer(), RecordContent::binary(), RecordType::record_type(), Mode::mode()) -> {Rid::rid(), RecordVersion::integer(), CollectionChanges::[collection_change()]} | error()

Create a new record.

You can set the VClusterId parameter to -1 to have OrientDB assign one for you (recommended).

  Data1 = #{"toto" => {integer, 42}, "tutu" => {string, "tutu"}},
  {Rid, 1, CollectionChanges} = odi:record_create(Con, -1, {"V", Data1}, document, sync).

record_delete/4

record_delete(C::pid(), RID::rid(), RecordVersion::pos_integer(), Mode::mode()) -> boolean() | error()

Delete a record by its RecordID.

record_load/4

record_load(C::pid(), X2::{ClusterId::integer(), RecordPosition::integer()}, FetchPlan::string() | default, IgnoreCache::boolean()) -> [fetched_record()] | error()

Load a record by RecordID, according to a fetch plan.

  [{true, document, Version, Class, Data} | CachedRecords] =
      odi:record_load(Con, {ClusterId, RecordPos}, "*:2", false).

record_update/6

record_update(C::pid(), RID::rid(), UpdateContent::boolean(), Record::record(), OldRecordVersion::pos_integer(), Mode::mode()) -> {RecordVersion::pos_integer(), CollectionChanges::[collection_change()]} | error()

Update a record. Returns the new record's version.

  Data2 = #{"x" => {string, "Y"}},
  {2, CollectionChange} = odi:record_update(Con2, Rid, false, {"V", Data2}, 1, sync).

record_update/7

record_update(C::pid(), RID::rid(), UpdateContent::boolean(), Record::binary(), OldRecordVersion::pos_integer(), RecordType::record_type(), Mode::mode()) -> {NewRecordVersion::pos_integer(), CollectionChanges::[collection_change()]} | error()

Update a record. Returns the new record's version.

script/3

script(C::pid(), Language::string(), Code::string()) -> {[fetched_record()], [fetched_record()]} | error()

Synchronous script.

  {[{{-1, -1}, document, 0, [], #{"result" := {integer, 4}}}], []} =
      odi:script(Con, "Javascript", "print('hello world'); 4").

script/5

script(C::pid(), Language::string(), Code::string(), SimpleParams::#{string() => any()} | null, ComplexParams::#{string() => {embedded_list, []}} | null) -> {[fetched_record()], [fetched_record()]} | error()

Synchronous script with parameters.

See also: script/3.

tx_commit/4

tx_commit(C::pid(), TxId::integer(), UsingLog::boolean(), Operations::[tx_operation()]) -> {CreatedRecords::[{ClientSpecifiedRid::rid(), ActualRid::rid()}], UpdatedRecords::[{UpdatedRid::rid(), NewRecordVersion::integer()}], CollectionChanges::[collection_change()]} | error()

Commits a transaction.

This operation flushes all the given changes to the server side in a single transaction.

  {IdRemaps, _Updates, _Changes} = = odi:tx_commit(Con, 1, true, [
      {create, {-1, -2}, document, {"V", Data1}},
      {update, {VClusterId1, RecordPos1}, document, 1, true, {"V", Data1b}},
      {delete, {VClusterId2, RecordPos2}, document, 1}
  ]).
Create operations can use -1 for the cluster IDs and other negative values for the record IDs. IdRemaps allows to know what was actually used.


Generated by EDoc