百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

oriento

> 编程语言
开源

以前的 OrientDB 官方 Node.js 驱动程序。速度快、体积小,使用二进制协议。现已过时。

195 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

以前的 OrientDB 官方 Node.js 驱动程序。速度快、体积小,使用二进制协议。现已过时。

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.

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.

bash
npm install oriento

Running Tests

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

bash
npm install

Then run the tests:

bash
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.

javascript
var Oriento = require('oriento');

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

Listing the databases on the server

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

Creating a new database

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

Using an existing database

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

Using an existing database with credentials

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

Execute an Insert Query

javascript
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

javascript
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

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

Query Builder: Insert Record

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

Query Builder: Update Record

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

Query Builder: Delete Record

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

Query Builder: Select Records

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

Query Builder: Text Search

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

Query Builder: Select Records with Fetch Plan

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

Query Builder: Select an expression

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

Query Builder: Traverse Records

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

Query Builder: Return a specific column

javascript
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

javascript
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

javascript
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

javascript
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

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

Loading a record by RID.

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

Deleting a record

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

Listing all the classes in the database

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

Creating a new class

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

Creating a new class that extends another

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

Getting an existing class

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

Updating an existing class

javascript
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

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

Adding a property to a class

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

Deleting a property from a class

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

Renaming a property on a class

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

Creating a record for a class

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

Listing records in a class

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

Create a new index for a class property

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

Get entry from class property index

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

Creating a new, empty vertex

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

Creating a new vertex with some properties

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

Deleting a vertex

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

Creating a simple edge between vertices

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

Creating an edge with properties

javascript
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

javascript
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.

javascript
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

javascript
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.

bash
  -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.

bash
oriento db list

Creating a new database

bash
oriento db creat

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言