Back Home

* http://www.slideshare.net/lvca/orient-db-introduction

Database and Schemas

OrientDb can be run

  • schemeless - where we don't define the index type and new fields can be added dynamically
  • scheme - where we explicitly add the schema and index type === Embedded (Json) documents === the Embedded type supports any valid Json document
orientdb> INSERT INTO examples (embedded) VALUES ({"name":"James","age":23})

allows us to

SELECT embedded.age  FROM examples
embedded
23

Embedset functions:

  • expand(embset) - extract each element of the set into individual row
  • first()
  • last()
  • size()
  • remove()
  • removeAll()
  • keys() e.g select embedded.keys() from examples
  • removeAll()
  • toJson()

Containers (set) datatype

A container is to support arrays, sets, lists objects:

 INSERT INTO Examples (embset) VALUES ([{"name":"John","age":24},{"name":"Barbara","age":23}])

This allows us to use set functions:

SELECT embset.size() FROM examples
embedset
2

Getting Strict

ALTER CLASS Posts STRICTMODE true

Relationships

OrientDB doesn't use JOINs. Instead it uses LINKs. A LINK is a relationship managed by storing the target RID in the source record. e.g Invoice → Customer, then you have a pointer to Customer inside Invoice as an attribute.

This means that a JOIN operation has no computational cost to retrieve a related document from a given one.

OrientDB supports different kinds of relationships:

  • LINK, to point to one record only
  • LINKSET, to point to several records. Like Java Sets, the same RID can only be included once. The pointers also have no order
  • LINKLIST, to point to several records. Like Java Lists, they are ordered and can contain duplicates
  • LINKMAP, to point to several records with a key stored in the source record. The Map values are the RIDs. Works like the Java Map<?,Record>.

OrientDb Rest Interface

  def url = "http://localhost:2480/database/demo"
		HttpClient client = new HttpClient()
		HttpMethod get = new GetMethod(url);
 
		Credentials credentials = new UsernamePasswordCredentials("admin", "admin");
		client.getState().setCredentials(AuthScope.ANY, credentials);
 
		client.executeMethod(get)
 
		def result = new groovy.json.JsonSlurper().parseText(  get.getResponseBodyAsString().toString())
		println "pretty printing .. "
		println JsonOutput.prettyPrint( get.getResponseBodyAsString().toString() )
 
orientdb.txt · Last modified: 2017/10/23 01:46 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd