DEV Community

Hartmut B.
Hartmut B.

Posted on • Edited on

Active Orient – Introduction & Overview

How about a (fast) open source database usable without any schema, query-able with sql-statements and able to perform sophisticated graph operations? Not to forget: Easily accessible via an intuitive ruby interface. The latter is ActiveOrient.

Prerequisites

git clone https://github.com/topofocus/active-orient.git
cd active-orient
bundle install; bundle update
Enter fullscreen mode Exit fullscreen mode

Now modify config/connect.yaml.
Test, development and production databases are created if they don't exist.

Then change to /bin and run

./active-orient-console -t
Enter fullscreen mode Exit fullscreen mode

Simple Start

Any database-class is recognized and allocated. Further, any class created in the process is usable immediately. The behavior of any Class can be customized in model-files, which are included upon the creation of a class.

The base-classes V)ertex and E)dge are always present. Its good practice, to inherent any user-class from the base-classes.

 # create a class
    V.create_class :m   # V is the base »vertex» class. M is the vertex-class created The corresponding database-class: »m«.
 # INFO->CREATE CLASS m EXTENDS 

 # create a record
    M.create name: 'Hugo', age: 46, interests: [ 'swimming', 'biking', 'reading' ]
 # INFO->CREATE VERTEX m CONTENT {"name":"Hugo","age":46,"interests":["swimming","biking","reading"]}
    # query the database
    hugo = M.where( name: 'Hugo' ).first
    hugo.to_human
    =>"<M[177:0]: age: 46, interests: [\"swimming\", \"biking\", \"reading\"], name : Hugo>" 
    # update the dataset
    hugo.update father: M.create( name: "Volker", age: 76 )  # we create an internal link
# INFO->CREATE VERTEX m CONTENT {"name":"Volker","age":76}
# INFO->update #177:0 set father = #178:0
    hugo.to_human
    => "<M[177:0]: age : 46, father : <M[178:0]: age : 76, name : Volker>, interests : [\"swimming\", \"biking\", \"reading\"], name : Hugo>"
    hugo.father.name    
    => volker
    # change array elements
    hugo.interests << "dancing"  # --> [ 'swimming', 'biking', 'reading', 'dancing' ]
#INFO->update #177:0  set interests = interests || ['dancing'] 

    M.remove hugo 
    M.delete_class  # removes the class from OrientDB and deletes the ruby-object-definition
Enter fullscreen mode Exit fullscreen mode

In this brief introduction, we created a Vertex-Class »M«. Then we created a document (record) with some properties. We queried the database using a syntax similar to ActiveRecord.
Then we created a self-refrencing link which we followed to access connected information.

At last – using the syntax of ruby-arrays – we added an entry to an embedded list. Anything without any configuration in schema-, model-files or whatsoever.

This ends Part 1 of the ActiveOrient Mini-Series.
The next part covers unidirectional links and joins, an introduction to sql-queries and their abstraction with Orientquery

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay