npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orientdb-rest-api

v1.1.2

Published

A node.js driver for OrientDB using the OrientDB RESTful HTTP protocol

Downloads

19

Readme

orientdb-rest-api

A Node.js driver to talk to the OrientDB REST API for node and the browser Also works with electron and react-native

Very basic http wrapper using superagent based on node-orient-http and tested on OrientDb 2.2.31

Install

npm install orientdb-rest-api

Basic Usage

const OrientDB=require('orientdb-rest-api');

const db = new OrientDB({
  user: 'root',
  password: 'root_passwd',
  host: 'http://localhost:2480',
  database: 'GratefulDeadConcerts',
})

db.connect().then(async ()=>{
  const result=await db.query('select * from V where name = ?',["Batman"])
  console.log(result)
}).catch(err=>{
  console.error(err.message)
})

Query and Command query

Syntax:

db.query(query, parameters, limit, fetchplan)
db.command(query, parameters, limit, fetchplan)

Examples:

db.command('insert into V set name = ?', ["Batman"]).then(async ()=>{
  // named parameters, no limit
  const res=await db.query('select * from V where name = :name', {
    name: "Batman"
  })
  db.command('select * from V where name = ?', ["Batman"], 1).then(successHandler)
}).catch((err)=>console.error(err))

Response will be something like:

{
  "result": [
    {
      "@type": "d",
      "@rid": "#9:12",
      "@version": 1,
      "@class": "V",
      "name": "Batman"
    }
  ]
}

Methods

All methods return a Promise
See superagent for more information about the response and errors

Connection

db.connect() returns boolean db.disconnect() returns boolean

Rest commands:

db.get(command, queryParams) returns object
db.delete(command, queryParams) returns boolean
db.head(command, queryParams) returns boolean

db.post(command, queryParams, postBody) returns object
db.put(command, queryParams, postBody) returns object
db.patch(command, queryParams, postBody) returns object

Custom commands

db.query(query, [paramenters, limit, fetchplan]) returns object containing the result of the query
db.command(query, [paramenters, limit, fetchplan]) returns object|boolean containing the result of the command
db.insert(className, data) returns boolean shortcut as db.post('document', null, data) and set '@class' property of data
db.queryOne(query, paramenters, fetchplan) returns Object|null shortcut for setting limit 1 and return either first result or null

Helpers

db.getDateTimeFormatted([fromDate]) return string returns a datetime formatted date. fromDate is optional, if not set, it will use current datetime
db.getDateFormatted([fromDate]) same as above

Examples:

// create
db.post('document', null, { '@class': 'V', name: 'Gustavo Salome'}).then().catch()

// deleting, should return true
db.delete('document', '9:1').then().catch()

// create as command, should return the new record
db.command('insert into V set name = "Batman"').then().catch()

db.query('select * from V where name = "Batman"').then((res)=>{
  console.log(res)
}, 1 /*1 is the limit*/).catch(err=>{
  console.log(err.message)
})

Language

db.language('gremlin').query("g.V('@class', 'User')").then(successHandler2).catch(errorHandler2)

See OrientDB-REST API for a full list of rest commands

Events

const db = new OrientDB({
  user: 'root',
  password: 'root_passwd',
  host: 'http://localhost:2480',
  database: 'GratefulDeadConcerts',
})

db.connect()
db.disconnect()
// once connected
db.once('connected', (response)=>{
  console.log('yes! connected')
})
// on any error
db.on('error',(message, err)=>{
  console.log(message, err)
})
db.once('disconnected', (response)=>{
  console.log('bye!')
})

Example

const OrientDB=require ('orientdb-rest-api')
const db=new OrientDB({
  user: 'root',
  password: 'password',
  host: 'http://localhost:2480',
  database: 'GratefulDeadConcerts',
})
const config=require('./config/local')
const db=new OrientDB(config)
db.connect().then(async (res)=>{
  console.log(res) // true
  res=await db.command('insert into V set name = ?', ["Batman"])
  console.log(res) // Object containing the new record
  res=await db.query('select * from V where name = :name', {
    name: "Batman"
  })
  console.log(res) // Object containing the fetched record
  res=await db.command('select * from V where name = ?', ["Batman"], 1)
  console.log(res) // Same object containing the fetched record
  res=await db.delete('document', res.result[0]['@rid'])
  console.log(res) // true
  res=await db.disconnect()
})
db.on('connected',(res)=>{
  console.log('connected')
})
db.on('error',(message, err)=>{
  console.log(message)
  process.exit()
})
db.on('disconnected',(res)=>{
  console.log('disconnected')
})

Api

See OrientDB-REST API for more docs.

Erros

Listening for error events

db.on('error',(message, err)=>{
  console.log(message, err)
})
db.query('error query').catch((err)=>{
  console.log(err.message)
})

See SuperAgent Error Handling for more information

Config

{
  user: 'root',
  password: 'root_passwd',
  host: 'http://127.0.0.1:2480',
  database: 'GratefulDeadConcerts',
  language: 'sql',
  timeout: 1000*5,
}

Changelog

1.1.0

  • Changed from axios to superagent

1.0.0

  • First Release