{
FirstName: "Bob",
LastName: "Smith",
Age: 27
}
{
FirstName: "Bob",
LastName: "Smith",
Age: 27,
Title: "Mr",
Nationality: "New Zealander"
}
# Location of OrientDB binaries
cd ~/Scripts/orientdb-graphed-1.5.0/bin/
# Start server
./server.sh
# Stop server
./shutdown.sh
# Location of OrientDB binaries
cd ~/Scripts/orientdb-graphed-1.5.0/bin/
# Open console to perform queries etc.
./console.sh
OrientDB has server users that can be found in config/orientdb-server-config.xml.
These are the users used to connect to the server and create databases.
<users>
<user resources="*" password="A5D6...H796" name="root"/>
<user resources="connect,server.listDatabases,server.dblist" password="guest" name="guest"/>
</users>
# Connect to the server
connect remote:localhost root [password]
# Create a database
create database remote:localhost/[dbname] root [password] plocal document
# Connect to the database
connect remote:localhost/[dbname] admin admin
Class is equivalent to table basically, OO ideas incorporated.
# List classes
list classes
# Create new class
create class Page
# Create abstract class
create class Person abstract
# Create concrete class from abstract
create class Student extends Person
# Create subclass
create class Freshman extends Student
# Display class structure
desc Student
# Create properties
create property Person.FirstName string
create property Person.Age integer
# Add constraint of minimum 3 characters
alter property Person.FirstName min 3
# Inserting multiple records
create class Posts
insert into Posts (Title,Text) values ("title 1","text 1"), ("title 2","text 2");
create property Posts.URLSegment string
insert into Posts (Title,URLSegment) values ("title 3","title-3");
# Select all records
select * from Posts
# More common:
select from Posts
# Particular record
select from #27:0
# Update a record
update #25:0 set Title = 'Post title 25:0'
# No double quote delimiters for class and property names
# This tries to find a field called "Title" (including quotes) to update
update #25:0 set "Title" = 'Some title'
# Delete a record
delete from #25:2
# Create structure
create class Parent
create class Child extends Parent
insert into Child (Name) values ("Eric Forman")
select from Child
# ----+-----+------------
# # |@RID |Name
# ----+-----+------------
# 0 |#16:0|Eric Forman
# ----+-----+------------
select from Parent
# ----+-----+------------
# # |@RID |Name
# ----+-----+------------
# 0 |#16:0|Eric Forman
# ----+-----+------------
insert into Parent (Name) values ("Red Forman")
select from Parent
# ----+-----+------------
# # |@RID |Name
# ----+-----+------------
# 0 |#15:0|Red Forman
# 1 |#16:0|Eric Forman
# ----+-----+------------
select from Child
# ----+-----+------------
# # |@RID |Name
# ----+-----+------------
# 0 |#16:0|Eric Forman
# ----+-----+------------
# Creating link for reference to an object in Authors class
create property Posts.Author link Authors
Use a "Link" data type to reference other objects
# Creating link sets for references to other types of objects
create property Posts.Categories LinkSet Categories
create property Categories.Posts LinkSet Posts
Use a container of references which can be one of 3 data types:
# Traverse Link
select Author.Name from #15:0
# Traverse containers
traverse Posts from #16:2
select from #18:0
# ----+-----+---------+-----------+----+----
# # |@RID |ClassName|Title |ID |Tags
# ----+-----+---------+-----------+----+----
# 0 |#18:0|Article |Article 278|18:0|[2]
# ----+-----+---------+-----------+----+----
traverse Tags from #18:0
# ----+-----+----+---------+-----------+----+-----+--------
# # |@RID |Tags|ClassName|Title |ID |Name |Articles
# ----+-----+----+---------+-----------+----+-----+--------
# 0 |#18:0|[2] |Article |Article 278|18:0|null |null
# 1 |#26:0|null|Tag |null |26:0|Tag 1|[1]
# 2 |#26:2|null|Tag |null |26:2|Tag 2|[1]
# ----+-----+----+---------+-----------+----+-----+--------