-
Notifications
You must be signed in to change notification settings - Fork 5
Properties
Although OrientDB has a schema-less-mode, where any properties are dynamically assigned, indexes and relations are as important as in conventional RDBMS.
ActiveOrient offers a Ruby way to define most common Properties and Indexes
ORD.create_class :M
--> INFO->CREATE CLASS M
=> M
M.properties
=> {:properties=>nil, :indexes=>nil}
M.create_property :symbol # the default-case: type: :string, no index
M.create_property :con_id, type: :integer
M.create_property :details, type: :link,
other_class: 'Contracts'
M.create_property :items, type: :linklist, :
linklist: Item
M.create_property :symbol
M.create_property :con_id, type: :integer
M.create_property :name, type: :string,
index: :unique
# or M.create_property( 'name' , type: :string){ :unique }
--> INFO->CREATE INDEX M.name UNIQUE
--> INFO->Index on M based on name created.
# try to define a link to a nonexisting class
M.create_property :details, type: :link, other_class: 'Contracts'
--> WARN->Classname "Contracts" ://: not present in temp
-->ERROR->Properties in M were NOT created
-->ERROR->The Error was: property named details is declared as LINK but linked Class is not declared
ORD.create_vertex_class :Contracts
--> INFO->CREATE CLASS Contracts EXTENDS V
=> Contracts
M.create_property :details, type: :link, other_class: 'Contracts'
pp M.properties
{:properties=>
[{"name"=>"symbol", "type"=>"STRING", ... }
{"name"=>"con_id", "type"=>"INTEGER", ... },
{"name"=>"name", "type"=>"STRING", ... },
{"name"=>"details", "linkedClass"=>"Contracts", "type"=>"LINK", ...},
],
:indexes=>[{"name"=>"M.name", "type"=>"UNIQUE", "fields"=>["name"]}]
}Indexes are essential to get the work done efficiently.
Apart from creating in the process of ActiveOrient provides a simple DSL to create them.
> Model.create_index name [, on: :automatic, type: :unique ]Its just a wrapper to the OrientDB CreateIndex command with some reasonable defaults.
One simple usecase is shown in `lib/model/e.rb'
class E < ActiveOrient::Model
class << self
=begin
Establish constrains on Edges
After applying this method Edges are uniq!
=end
def uniq_index
create_property :in, type: :link, linked_class: :V
create_property :out, type: :link, linked_class: :V
create_index "#{ref_name}_idx", on: [ :in, :out ]
end
end
> ORD.create_edge_class :my_edge
INFO->CREATE CLASS hc_my_edge EXTENDS E
=> HC::MY_EDGE
> HC::MY_EDGE.uniq_index
INFO->CREATE INDEX hc_my_edge_idx ON hc_my_edge(in, out) UNIQUE
INFO->Index on hc_my_edge based on hc_my_edge_idx created.
> HC::MY_EDGE.indexes
=> [{"name"=>"hc_my_edge_idx", "type"=>"UNIQUE", "fields"=>["in", "out"]}] Intention of the DSL is to provide a method to initialize a database structure via a readable script.
There is no explicit DSL to drop an Index.
This can be obtained with plain vanilla orientdb console commands:
## Example in ActiveOrient console
> HC::PortfolioPositions.indexes
=> [{"name"=>"hc_portfolio_positions.contract", "type"=>"UNIQUE", "fields"=>["contract"]}]
> ORD.execute { "DROP INDEX hc_portfolio_positions.contract" }
INFO->DROP INDEX hc_portfolio_positions.contract
=> [["drop index", "hc_portfolio_positions.contract"]]
> HC::PortfolioPositions.indexes
=> nil (to be continued)
Overview
Data Management
- Joining Tables, embedded Lists
- Links and Link Lists
- Relations
- Bidirectional Connections
- Working with Hashes
Public API
- Database
- Model CRUD
Misc