-
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.
If Dates and Times should be stored natively, this has to be declared via create_property
Otherwise they are stored as string and have to be parsed later.
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,
linked_class: Contracts # notice the Class-name here
M.create_property :items, type: :link_list,
linked_class: Item
M.create_property( :name ){ :unique } # create an automatic index, too
M.print_properties
=>> Detected Properties for class m
m.symbol -> STRING
m.con_id -> INTEGER
m.name -> STRING
m.details -> LINK -> contracts
:bool, :double, :datetime = :date, :float, :decimal,
:embedded_list = :list, :embedded_map = :map, :embedded_set = :set,
:int, :integer, :link_list, :link_map, :link_set, :string
Indexes are essential to get the work done efficiently.
Apart from creating in the process of creating a property ActiveOrient provides a simple DSL to create them separately.
> Model.create_index name [, on: » property, array of properties«, type: »:unique, :notunique « ]
Its just a wrapper to the OrientDB CreateIndex
command with some reasonable defaults.
:unique, :notunique, :dictionary, :fulltext,
:unique_hash_index, :notunique_hash_index, :dictionary_hash_index, :fulltext_hash_index,
:spatial
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