ArangoDB Object Modeling for Node.js, Foxx and Modern Web Browsers
Orango is an ODM (Object Data Modeler), an ORM (Object Relational Mapper) and an OGM (Object Graphical Mapper) in one that provides the following features:
- Central connectivity to ArangoDB
- Automated creation of collections and indexes
- Create schemas for data
- Interact with models to handle data-centric functionality
- Pre-populate database
- Graph linking and querying
- and more...
Why use Orango with ArangoDB?
- Ease of use
- Model-driven data
- Focus on data instead of queries
- Optimized query creation
- Validation
- Filter unknown data from being injected into database
- Cleaner interfaces
- Single point of change for bug fixes, features, etc
- Save on redundancy - DRY implementation
- Default values
- and more...
Community Support
Documentation & Articles
Official documentation can be found at orango.js.org. (This is a work in progress)
I will be regularly posting articles on CodeBurst.io (Medium). Follow me there https://codeburst.io/@roboncode
Follow me on Twitter https://twitter.com/@roboncode for updates
Installation
First be sure you have ArangoDB and Node.js installed. You can install ArangoDB using the official docker container.
Next, install Orango from the command line using npm
:
$ npm install orango
Importing
// Using Node.js `require()`const orango = // Using ES6 imports
Overview
Connecting to ArangoDB
First, we need to define a connection. If your app uses the default _system
database, you can connect using orango.connect()
. If you need to create additional connections, use orango.get( database:String ).connect()
.
The method connect([{url:String="http://localhost:8529", username:String, password:String}])
takes database name with options to establish a connection. Otherwise, it will use the default values.
const orango = const EVENTS = orangoconsts orangoevents orangoevents { await orango}
Note: Orango buffers model definitions, so they can be defined before or after a connection is established.
Defining a Model
const schema = author: String title: String body: String date: Date orango
Aside from defining the structure of your documents and data types, Orango models can handle the definition of:
- Validators
- Default values
- Indexes
- Static methods
- Computed properties
- Hooks
- Custom queries
- Unknown property filters
- JSON to model structures
- Joi definitions
The following example shows some of these features:
const Joi = const SCHEMA = orangoconsts Schema // computed properties { return thisfirstName + ' ' + thislastName } let schema = firstName: String lastName: String // Joi can be used directly email: Joi // JSON gets converted to Joi data types automatically age: type: Number min: 18 bio: type: String regex: /[a-z]/ // default values are supported on insert and update created: type: Date default: Datenow updated: type: Date defaultOnUpdate: Datenow schemaschema let User = orango // extend your model with custom functionsUser { return await this}
In code somewhere else
const User = orango ... let user = await Userconsole // access model getter
Examples
A growing set of examples are available here. To run the examples, clone
this project and then run the Orango docker containers.
Install dependencies
npm install
Run the docker containers provided by Orango
Linux and Mac
Run the ArangoDB containers provided by Orango.
$ make dbs
Windows
$ cd docker & docker-compose up -d
Run examples
npm run examples
You will be presented with a wizard where you can run different examples files.
Debugging the examples with VSCode
Setup your config like the example below. You can launch any number of the snippets by placing the snippet you would like to start in the args
array. Then run the debugger. The output will be in the Debug Console
.
License
Copyright (c) 2018-present, Rob Taylor