Skip to content

Model CRUD

Hartmut Bischoff edited this page Mar 4, 2021 · 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

note: if a vertex is deleted, all connected edges are removed, too

NULL Values

In ruby, a variable is reset by assignment with nil. If some database property should be erased, its set to NULL.

 > T.update set: { some_property :  nil }
 > T.where some_property: [nil]
 > T.count where: { some_property: [nil] }

If a query is fired, the database is asked whether a property is NULL. This has to be coded via an Array containing nil.

Clone this wiki locally