• Stars
    star
    327
  • Rank 124,631 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The official fast, lightweight node.js client for OrientDB

OrientJS driver

Official orientdb driver for node.js. Fast, lightweight, uses the binary protocol.

Build Status Coverage Status npm version npm downloads

NOTE: Release v3.0 provides new APIs in order to support OrientDB 3.0 features.

Features

  • Tested with latest OrientDB (2.2.x and 3.0.x).
  • Intuitive API, based on bluebird promises.
  • Fast binary protocol parser.
  • Streaming Support
  • Stateful Transaction Support
  • Distributed Support
  • Access multiple databases via the same socket (Session Pooling).
  • Connection Pooling
  • Migration support.
  • Simple CLI.

Versions and Compatibility

OrientJS v3.0 contains backwards compatible APIs for OrientDB 2.2.x and OrientDB 3.0.x using the old protocol version 33 (Legacy). New APIs are shipped in v3.0 to support the new protocol featuring Streaming, Stateful transactions, new SQL engine etc..

Resources

Installation

Install via npm.

npm install orientjs

For Typescript usage :

npm install @types/orientjs

Quick Start

Connect to OrientDB

Use the connect function in order to create a new OrientDBClient instance.

const OrientDBClient = require("orientjs").OrientDBClient;

OrientDBClient.connect({
  host: "localhost",
  port: 2424
}).then(client => {
  return client.close();
}).then(()=> {
   console.log("Client closed");
});

Single Session

To open a new standalone session use the client.session api. This api will create a new stateful session associated with the given database and credentials. Once done, call session.close in order to release the session on the server. Session are stateful since OrientJS 3.0 as they can execute server side transactions.

client.session({ name: "demodb", username: "admin", password: "admin" })
.then(session => {
	// use the session
	... 
	// close the session
	return session.close();
});

Pooled Sessions

Opening and closing sessions everytime can be expensive, since open and close require a network request to the server. Use the API client.sessions to create a pool of sessions with a given database and credentials. To get a session from the pool call the api pool.acquire. Once done with the session you can return the session to the pool by calling session.close

// Create a sessions Pool
client.sessions({ name: "demodb", username: "admin", password: "admin", pool: { max: 10} })
  .then(pool => {
    // acquire a session
    return pool.acquire()
      .then(session => {
        // use the session
        ...
        // release the session
        return session.close();
      })
      .then(() => {
      	 // close the pool
        return pool.close();
      });
  });
});

Session API

Once obtained a session using the above APIs you can:

  • Run a Query (Idempotent SQL statement)
  • Run a Command (Idempotent or non idempotent SQL statement)
  • Run a Transaction
  • Run a live query

Query

Streaming

session.query("select from OUser where name = :name", {params: { name: "admin" }})
.on("data", data => {
	console.log(data);
})
.on('error',(err)=> {
  console.log(err);
})
.on("end", () => {
	console.log("End of the stream");
});

or use .all API that convert the stream to a Promise and collect the result set into an array

session.query("select from OUser where name = :name", { params : {name: "admin" }})
.all()
.then((results)=> {
	console.log(results);
});

Command

session.command("insert into V set name = :name", {params: { name: "test" }})
.all()
.then(result => {
	console.log(result);
});

Transaction

Use the api session.runInTransaction in order to run a unit of work in a managed transaction (begin/commit/retry)

session.runInTransaction((tx)=>{
	return tx.command("insert into V set name = :name", {params: { name: "test" }}).all()
}).then(({result,tx}) => {
	console.log(result);
	console.log(tx);
});

Live Queries

session.liveQuery("select from V").on("data", data => {
	console.log(data);
});

Running Tests

To run the test suite, first invoke the following command within the repo, installing the development dependencies:

npm install

Then run the tests:

npm test

History

In 2012, Gabriel Petrovay created the original node-orientdb library, with a straightforward callback based API.

In early 2014, Giraldo Rosales made a whole host of improvements, including support for orientdb 1.7 and switched to a promise based API.

Later in 2014, codemix refactored the library to make it easier to extend and maintain, and introduced an API similar to nano. The result is so different from the original codebase that it warranted its own name and npm package. This also gave us the opportunity to switch to semantic versioning.

In June 2015, Orient Technologies company officially adopted the Oriento driver and renamed it as OrientJS.

Notes for contributors

Please see CONTRIBUTING.

Building from the Source Code

When building from source code, you need to download the driver directly from GitHub, then run NPM against the branch you want to use or test.

  1. Using Git, clone the package repository, then enter the new directory:

    $ git clone https://github.com/orientechnologies/orientjs.git
    $ cd orientjs
    
  2. When you clone the repository, Git automatically provides you with the current state of the master branch. If you would like to work with another branch, like develop or test features on past releases, you need to check out the branch you want. For instance,

    $ git checkout develop
    
  3. Once you've selected the branch you want to build, call NPM to handle the installation.

    $ npm install
    
  4. Run the tests to make sure it works:

    $ npm test
    

Changes

See CHANGELOG

License

Apache 2.0 License, see LICENSE

More Repositories

1

orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
Java
4,696
star
2

spring-data-orientdb

OrientDB implementation for SpringData
Java
128
star
3

orientdb-studio

Studio web tool
HTML
128
star
4

OrientDB-NET.binary

C#/.NET binary driver for OrientDB
C#
92
star
5

orientdb-gremlin

TinkerPop3 Graph Structure Implementation for OrientDB
Java
90
star
6

orientdb-docs

Repository of the entire OrientDB documentation.
CSS
57
star
7

orientdb-lucene

Lucene indexes for OrientDB
Java
35
star
8

orientdb-etl

OrientDB ETL tools
Java
34
star
9

orientdb-js

New Javascript driver for OrientDB with a Blueprints/Gremlin like syntax. This library was an experiment and hasn't been maintained for long time. If you're using Node.js, we suggest to use https://github.com/orientechnologies/orientjs instead.
JavaScript
26
star
10

spark-orientdb

Apache Spark datasource for OrientDB
Scala
19
star
11

orientdb-jdbc

OrientDB JDBC Driver
Java
18
star
12

orientdb-labs

OrientDB Labs hosts last development version of OrientDB.
CSS
17
star
13

OrientDB.Net.Core

Experimental Modular OrientDB .Net Core Driver.
C#
15
star
14

orientdb-elasticsearch

OrientDB Elastic Search Plugin
Java
9
star
15

public-databases

This repository contains the registry of OrientDB public databases.
7
star
16

orientjs-native

OrientJS native implementation that use C++ lib for binary protocol
C++
6
star
17

teleporter

Automatically synchronizes any database in RDBMS to OrientDB database. Open Source Project - Apache 2 license.
Java
6
star
18

orientdb-spatial

OrientDB plugin to manage spatial indexes, this have been moved to https://github.com/orientechnologies/orientdb/tree/develop/lucene.
Java
5
star
19

orientdb-helm

Helm chart for OrientDB
Smarty
4
star
20

orientdb-neo4j-importer-plugin

Neo4j importer for OrientDB runnable as plugin inside the server.
Java
4
star
21

extra-functions

Extra SQL functions to install into the OrientDB Server
Kotlin
4
star
22

OrientDB.Net

OrientDB .Net Core core modules solution.
C#
4
star
23

orientjs-example

HTML
4
star
24

orientdb-benchmarks

OrientDB Benchmark suite
Java
3
star
25

OrientDB.Net.Serializers.RecordCSVSerializer

OrientDB.Net.Serializers.RecordCSVSerializer
C#
3
star
26

orientc

OrientDB C serialization library
C++
2
star
27

OrientDB.Net.SqlCommandBuilder

SQL Command Builder for OrientDB.Net.Core projects.
C#
2
star
28

dotnet-driver

Experimental .net driver for OrientDB
2
star
29

OrientDB.Net.ConnectionProtocols.Binary

OrientDB.Net SDK implementation of the the binary protocol.
C#
2
star
30

orientdb-security

OrientDB Security plugin moved to https://github.com/orientechnologies/orientdb
Java
1
star