Skip to content

Model CRUD

topofocus edited this page Jul 15, 2019 · 3 revisions

Public API for ActiveOrient::Base-Model Objects

Create a database class

#ORD Points to the OrientDB-Instance
 ORD.create_class {class_name [, class_name , ...]} # String or Symbol    ## returns allocated class
 Klass.create_class {class_name [, class_name}, ...]}                     ## creates inherited classes
# special cases
 V.create_class class_names                     # creates vertex classes
 E.create_class class_names                     # creates edge classes

Creation and update of a single document

 V.create_class :t 
 t = T.create  property: value , (...)         # creates a document, attributes go into the Hash
 t.update  property: value                     # updates the document, 
# or
 t.{property} = {value}
 t.save

Update and Upsert ( query database and modify accordingly )

 V.create_class :t 
 T.update set:{ attributes }, where: { condition }
 T.upsert set:{ attributes }, where: { condition }  # create a document, if where cause reveals no match

Delete

 V.create_class :t 
 # a single document
 t = T.create attr: 'value' 
 t.delete

 # several documents
 T.delete where: {attr: 'value'}  || T.delete where: 'a valid condition'

 # any document of database class
 T.delete all: true

(remember: if a vertex is deleted, all connected edges are removed, too)

Clone this wiki locally