• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

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

Repository Details

Former official node.js driver for OrientDB. Fast, lightweight, uses the binary protocol. Now deprecated.

NOTE: Oriento is deprecated, development continues at https://github.com/orientechnologies/orientjs

Oriento

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

Build Status Gitter chat

Supported Versions

Oriento aims to work with version 1.7.1 of orientdb and later. While it may work with earlier versions, they are not currently supported, pull requests are welcome!

IMPORTANT: Oriento does not currently support OrientDB's Tree Based RIDBag feature because it relies on making additional network requests. This means that by default, the result of e.g. JSON.stringify(record) for a record with up to 119 edges will be very different from a record with 120+ edges. This can lead to very nasty surprises which may not manifest themselves during development but could appear at any time in production. There is an open issue for this in OrientDB, until that gets fixed, it is strongly recommended that you set RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD to a very large value, e.g. 2147483647. Please see the relevant section in the OrientDB manual for more information.

Installation

Install via npm.

npm install oriento

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

Features

  • Tested with latest orientdb (1.7).
  • Intuitive API, based on bluebird promises.
  • Fast binary protocol parser.
  • Access multiple databases via the same socket.
  • Migration support.
  • Simple CLI.
  • Connection Pooling

Usage

Configuring the client.

var Oriento = require('oriento');

var server = Oriento({
  host: 'localhost',
  port: 2424,
  username: 'root',
  password: 'yourpassword'
});

Listing the databases on the server

server.list()
.then(function (dbs) {
  console.log('There are ' + dbs.length + ' databases on the server.');
});

Creating a new database

server.create({
  name: 'mydb',
  type: 'graph',
  storage: 'plocal'
})
.then(function (db) {
  console.log('Created a database called ' + db.name);
});

Using an existing database

var db = server.use('mydb');
console.log('Using database: ' + db.name);

Using an existing database with credentials

var db = server.use({
  name: 'mydb',
  username: 'admin',
  password: 'admin'
});
console.log('Using database: ' + db.name);

Execute an Insert Query

db.query('insert into OUser (name, password, status) values (:name, :password, :status)',
  {
    params: {
      name: 'Radu',
      password: 'mypassword',
      status: 'active'
    }
  }
).then(function (response){
  console.log(response); //an Array of records inserted
});

Execute a Select Query with Params

db.query('select from OUser where name=:name', {
  params: {
    name: 'Radu'
  },
  limit: 1
}).then(function (results){
  console.log(results);
});

Raw Execution of a Query String with Params

db.exec('select from OUser where name=:name', {
  params: {
    name: 'Radu'
  }
}).then(function (response){
  console.log(response.results);
});

Query Builder: Insert Record

db.insert().into('OUser').set({name: 'demo', password: 'demo', status: 'ACTIVE'}).one()
.then(function (user) {
  console.log('created', user);
});

Query Builder: Update Record

db.update('OUser').set({password: 'changed'}).where({name: 'demo'}).scalar()
.then(function (total) {
  console.log('updated', total, 'users');
});

Query Builder: Delete Record

db.delete().from('OUser').where({name: 'demo'}).limit(1).scalar()
.then(function (total) {
  console.log('deleted', total, 'users');
});

Query Builder: Select Records

db.select().from('OUser').where({status: 'ACTIVE'}).all()
.then(function (users) {
  console.log('active users', users);
});

Query Builder: Text Search

db.select().from('OUser').containsText({name: 'er'}).all()
.then(function (users) {
  console.log('found users', users);
});

Query Builder: Select Records with Fetch Plan

db.select().from('OUser').where({status: 'ACTIVE'}).fetch({role: 5}).all()
.then(function (users) {
  console.log('active users', users);
});

Query Builder: Select an expression

db.select('count(*)').from('OUser').where({status: 'ACTIVE'}).scalar()
.then(function (total) {
  console.log('total active users', total);
});

Query Builder: Traverse Records

db.traverse().from('OUser').where({name: 'guest'}).all()
.then(function (records) {
  console.log('found records', records);
});

Query Builder: Return a specific column

db
.select('name')
.from('OUser')
.where({status: 'ACTIVE'})
.column('name')
.all()
.then(function (names) {
  console.log('active user names', names.join(', '));
});

Query Builder: Transform a field

db
.select('name')
.from('OUser')
.where({status: 'ACTIVE'})
.transform({
  status: function (status) {
    return status.toLowerCase();
  }
})
.limit(1)
.one()
.then(function (user) {
  console.log('user status: ', user.status); // 'active'
});

Query Builder: Transform a record

db
.select('name')
.from('OUser')
.where({status: 'ACTIVE'})
.transform(function (record) {
  return new User(record);
})
.limit(1)
.one()
.then(function (user) {
  console.log('user is an instance of User?', (user instanceof User)); // true
});

Query Builder: Specify default values

db
.select('name')
.from('OUser')
.where({status: 'ACTIVE'})
.defaults({
  something: 123
})
.limit(1)
.one()
.then(function (user) {
  console.log(user.name, user.something);
});

Query Builder: Put a map entry into a map

db
.update('#1:1')
.put('mapProperty', {
  key: 'value',
  foo: 'bar'
})
.scalar()
.then(function (total) {
  console.log('updated', total, 'records');
});

Loading a record by RID.

db.record.get('#1:1')
.then(function (record) {
  console.log('Loaded record:', record);
});

Deleting a record

db.record.delete('#1:1')
.then(function () {
  console.log('Record deleted');
});

Listing all the classes in the database

db.class.list()
.then(function (classes) {
  console.log('There are ' + classes.length + ' classes in the db:', classes);
});

Creating a new class

db.class.create('MyClass')
.then(function (MyClass) {
  console.log('Created class: ' + MyClass.name);
});

Creating a new class that extends another

db.class.create('MyOtherClass', 'MyClass')
.then(function (MyOtherClass) {
  console.log('Created class: ' + MyOtherClass.name);
});

Getting an existing class

db.class.get('MyClass')
.then(function (MyClass) {
  console.log('Got class: ' + MyClass.name);
});

Updating an existing class

db.class.update({
  name: 'MyClass',
  superClass: 'V'
})
.then(function (MyClass) {
  console.log('Updated class: ' + MyClass.name + ' that extends ' + MyClass.superClass);
});

Listing properties in a class

MyClass.property.list()
.then(function (properties) {
  console.log('The class has the following properties:', properties);
});

Adding a property to a class

MyClass.property.create({
  name: 'name',
  type: 'String'
})
.then(function () {
  console.log('Property created.')
});

Deleting a property from a class

MyClass.property.drop('myprop')
.then(function () {
  console.log('Property deleted.');
});

Renaming a property on a class

MyClass.property.rename('myprop', 'mypropchanged');
.then(function () {
  console.log('Property renamed.');
});

Creating a record for a class

MyClass.create({
  name: 'John McFakerton',
  email: '[email protected]'
})
.then(function (record) {
  console.log('Created record: ', record);
});

Listing records in a class

MyClass.list()
.then(function (records) {
  console.log('Found ' + records.length + ' records:', records);
});

Create a new index for a class property

db.index.create({
  name: 'MyClass.myProp',
  type: 'unique'
})
.then(function(index){
  console.log('Created index: ', index);
});

Get entry from class property index

db.index.get('MyClass.myProp')
.then(function (index) {
  index.get('foo').then(console.log.bind(console));
});

Creating a new, empty vertex

db.create('VERTEX', 'V').one()
.then(function (vertex) {
  console.log('created vertex', vertex);
});

Creating a new vertex with some properties

db.create('VERTEX', 'V')
.set({
  key: 'value',
  foo: 'bar'
})
.one()
.then(function (vertex) {
  console.log('created vertex', vertex);
});

Deleting a vertex

db.delete('VERTEX')
.where('@rid = #12:12')
.one()
.then(function (count) {
  console.log('deleted ' + count + ' vertices');
});

Creating a simple edge between vertices

db.create('EDGE', 'E')
.from('#12:12')
.to('#12:13')
.one()
.then(function (edge) {
  console.log('created edge:', edge);
});

Creating an edge with properties

db.create('EDGE', 'E')
.from('#12:12')
.to('#12:13')
.set({
  key: 'value',
  foo: 'bar'
})
.one()
.then(function (edge) {
  console.log('created edge:', edge);
});

Deleting an edge between vertices

db.delete('EDGE', 'E')
.from('#12:12')
.to('#12:13')
.scalar()
.then(function (count) {
  console.log('deleted ' + count + ' edges');
});

Creating a function

You can create a function by supplying a plain javascript function. Please note that the method stringifies the function passed so you can't use any varaibles outside the function closure.

db.createFn("nameOfFunction", function(arg1, arg2) {
  return arg1 + arg2;
})
.then(function (count) {
  // Function created!
});

You can also omit the name and it'll default to the Function#name

db.createFn(function nameOfFunction(arg1, arg2) {
  return arg1 + arg2;
})
.then(function (count) {
  // Function created!
});

CLI

An extremely minimalist command line interface is provided to allow databases to created and migrations to be applied via the terminal.

To be useful, oriento requires some arguments to authenticate against the server. All operations require the password argument unless the user is configured with an empty password. For operations that involve a specific db, include the dbname argument (with dbuser and dbpassword if they are set to something other than the default).

You can get a list of the supported arguments using oriento --help.

  -d, --cwd         The working directory to use.
  -h, --host        The server hostname or IP address.
  -p, --port        The server port.
  -u, --user        The server username.
  -s, --password    The server password.
  -n, --dbname      The name of the database to use.
  -U, --dbuser      The database username.
  -P, --dbpassword  The database password.
  -?, --help        Show the help screen.

If it's too tedious to type these options in every time, you can also create an oriento.opts file containing them. Oriento will search for this file in the working directory and apply any arguments it contains. For an example of such a file, see test/fixtures/oriento.opts.

Note: For brevity, all these examples assume you've installed oriento globally (npm install -g oriento) and have set up an oriento.opts file with your server and database credentials.

Database CLI Commands.

Listing all the databases on the server.

oriento db list

Creating a new database

oriento db create mydb graph plocal

Destroying an existing database

oriento db drop mydb

Migrations

Oriento supports a simple database migration system. This makes it easy to keep track of changes to your orientdb database structure between multiple environments and distributed teams.

When you run a migration command, oriento first looks for an orient class called Migration. If this class doesn't exist it will be created. This class is used to keep track of the migrations that have been applied.

Oriento then looks for migrations that have not yet been applied in a folder called migrations. Each migration consists of a simple node.js module which exports two methods - up() and down(). Each method receives the currently selected database instance as an argument.

The up() method should perform the migration and the down() method should undo it.

Note: Migrations can incur data loss! Make sure you back up your database before migrating up and down.

In addition to the command line options outlined below, it's also possible to use the migration API programatically:

var db = server.use('mydb');

var manager = new Oriento.Migration.Manager({
  db: db,
  dir: __dirname + '/migrations'
});

manager.up(1)
.then(function () {
  console.log('migrated up by one!')
});

Listing the available migrations

To list all the unapplied migrations:

oriento migrate list

Creating a new migration

oriento migrate create my new migration

creates a file called something like m20140318_200948_my_new_migration which you should edit to specify the migration up and down methods.

Migrating up fully

To apply all the migrations:

oriento migrate up

Migrating up by 1

To apply only the first migration:

oriento migrate up 1

Migrating down fully

To revert all migrations:

oriento migrate down

Migrating down by 1

oriento migrate down 1

Events

You can also bind to the following events

beginQuery

Given the query

db.select('name, status').from('OUser').where({"status": "active"}).limit(1).fetch({"role": 1}).one();

The following event will be triggered

db.on("beginQuery", function(obj) {
  // => {
  //  query: 'SELECT name, status FROM OUser WHERE status = :paramstatus0 LIMIT 1',
  //  mode: 'a',
  //  fetchPlan: 'role:1',
  //  limit: -1,
  //  params: { params: { paramstatus0: 'active' } }
  // }
});

endQuery

After a query has been run, you'll get the the following event emitted

db.on("endQuery", function(obj) {
  // => {
  //   "err": errObj,
  //   "result": resultObj,
  //   "perf": {
  //     "query": timeInMs
  //   }
  // }
});

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.

Notes for contributors

Please see CONTRIBUTING.

Changes

See CHANGELOG

License

Apache 2.0 License, see LICENSE

More Repositories

1

fast.js

Faster user-land reimplementations for several common builtin native JavaScript functions.
JavaScript
3,412
star
2

ts-sql

A SQL database implemented purely in TypeScript type annotations.
TypeScript
3,181
star
3

babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
JavaScript
886
star
4

deprank

Use PageRank to find the most important files in your codebase.
TypeScript
878
star
5

yii2-localeurls

Automatic locale/language management for URLs
PHP
412
star
6

babel-plugin-closure-elimination

A Babel plugin which eliminates closures from your JavaScript wherever possible.
JavaScript
369
star
7

babel-plugin-contracts

Design by Contract for JavaScript via a Babel plugin.
JavaScript
266
star
8

babel-plugin-macros

Hygienic, non-syntactic macros for JavaScript via a Babel plugin.
JavaScript
261
star
9

htmling

Polymer / HTML5 templating syntax for node.js
JavaScript
177
star
10

yii2-dockerized

A template for docker based Yii 2 applications
PHP
169
star
11

yii2-excelexport

A utility to quickly create Excel files from query results or raw data
PHP
102
star
12

gitignore-parser

A simple .gitignore parser for node.js
JavaScript
97
star
13

contractual

Unobtrusive, backwards compatible, syntactic sugar for Design by contract in JavaScript.
JavaScript
72
star
14

babel-plugin-trace

This is a Babel plugin which adds a straightforward, declarative syntax for adding debug logging to JavaScript applications.
JavaScript
63
star
15

yii2-configloader

Build configuration arrays from config files and env vars.
PHP
61
star
16

yii2-streamlog

A Yii 2 log target for streams in URL format
PHP
52
star
17

yii2-dockerbase

Yii 2 base image for dockerized yii2 projects
Shell
39
star
18

YiiElasticSearch

Elastic Search client for Yii
PHP
33
star
19

malloc

Simple malloc() & free() implementation for node.js, built on top of array buffers.
JavaScript
25
star
20

reign

A persistent, typed objects implementation for node.js and the browser.
JavaScript
23
star
21

binary-protocol

Easy, fast, writers and readers for implementing custom binary protocols in node.js.
JavaScript
20
star
22

oauth2yii

An OAuth2 client / server extension for the Yii framework
PHP
17
star
23

modeling

Fast and flexible data models for node.js and the browser.
JavaScript
15
star
24

restyii

A RESTful extension for Yii.
PHP
15
star
25

babel-plugin-hyperhtml

Babel plugin which compiles JSX into hyperHTML
JavaScript
12
star
26

yii2-excel-message

Translate messages via Excel files
PHP
12
star
27

backing

Provides a virtual address space for large segments of memory via JavaScript ArrayBuffers, and operations for allocating and freeing within the address space, optionally via a simple reference counting garbage collector.
JavaScript
11
star
28

validating

Quick and easy validators for node.js and the browser.
JavaScript
10
star
29

babel-plugin-conditional

Conditionally applies a set of babel plugins based on the result of an expression evaluated at runtime.
JavaScript
10
star
30

yii2-bs3activeform

A Bootstrap 3 enhanced ActiveForm for Yii 2
PHP
9
star
31

url-route

Web component providing URL routing
JavaScript
9
star
32

htmling-demo-app

HTMLing demo running on express
CSS
8
star
33

garbage-collector

A garbage collector for JavaScript built on top of typed arrays.
JavaScript
8
star
34

geonames-importer

Imports geonames data into elasticsearch
JavaScript
7
star
35

orientdb-protobufs

An experiment to see how the orientdb binary protocol could look if it used protocol buffers.
Java
6
star
36

handlebarsphp

Transpiles handlebars templates into native PHP templates
PHP
6
star
37

atomicbuffers

Atomic `readInt32()`, `writeInt32()`, `readUInt32()` and `writeUInt32()` for node.js buffers.
JavaScript
6
star
38

classing

Fluent classes for node.js and the browser.
JavaScript
6
star
39

dispatching

Tiny routing / dispatch library for node and the browser.
JavaScript
5
star
40

casting

Tiny type casting library for node.js and the browser.
JavaScript
5
star
41

php-orientdb

A fast PHP driver for the OrientDB binary protocol.
PHP
5
star
42

obligations

Tiny JavaScript library for preconditions and postconditions, intended for use with Contractual.
JavaScript
4
star
43

AccessRestrictable

A Yii ActiveRecordBehavior that automatically applies conditions for access restriction to every query.
PHP
2
star
44

component-testing-library

A library for testing component driven UIs
TypeScript
2
star
45

bootstrap-css

Twitter Bootstrap CSS / LESS packaged for component.js instead of bower
CSS
2
star
46

miming

Processing and formatting for various mime types.
JavaScript
2
star
47

bs3activeform

A lightweight utility to render Bootstrap 3 forms in Yii
PHP
2
star
48

handlebarsgen

An extendable static code generator for handlebars templates, targetting languages other than JavaScript, e.g. PHP
CoffeeScript
2
star
49

malloc-append

Simple append-only alloc() implementation on top of buffers and array buffers.
JavaScript
1
star
50

jsx-email-nextjs

Reproduce an error with renderToStaticMarkup() in Next.js
TypeScript
1
star
51

bootstrap-tooltip

Twitter Bootstrap Tooltip plugin packaged for component.js instead of bower
JavaScript
1
star
52

bencha

Mocha-esque UI for the excellent benchmarkjs benchmarking library
CoffeeScript
1
star
53

bootstrap-transition

Twitter Bootstrap Transition plugin packaged for component.js instead of bower
JavaScript
1
star
54

urlrouter

Tiny URL routing for the browser
CoffeeScript
1
star
55

bootstrap-affix

Twitter Bootstrap Affix plugin packaged for component.js instead of bower
JavaScript
1
star
56

bootstrap-scrollspy

Twitter Bootstrap Scrollspy plugin packaged for component.js instead of bower
JavaScript
1
star