active-orient 0.42 → 0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile +13 -5
- data/Guardfile +12 -4
- data/README.md +67 -280
- data/VERSION +1 -1
- data/active-orient.gemspec +6 -5
- data/bin/active-orient-0.6.gem +0 -0
- data/bin/active-orient-console +85 -0
- data/config/boot.rb +72 -1
- data/config/config.yml +10 -0
- data/config/connect.yml +9 -4
- data/examples/books.rb +92 -40
- data/examples/streets.rb +89 -85
- data/examples/test_commands.rb +97 -0
- data/examples/test_commands_2.rb +59 -0
- data/examples/test_commands_3.rb +55 -0
- data/examples/test_commands_4.rb +33 -0
- data/examples/time_graph.md +162 -0
- data/lib/active-orient.rb +75 -9
- data/lib/base.rb +238 -169
- data/lib/base_properties.rb +68 -60
- data/lib/class_utils.rb +226 -0
- data/lib/database_utils.rb +98 -0
- data/lib/init.rb +79 -0
- data/lib/java-api.rb +442 -0
- data/lib/jdbc.rb +211 -0
- data/lib/model/custom.rb +26 -0
- data/lib/model/edge.rb +70 -0
- data/lib/model/model.rb +134 -0
- data/lib/model/the_class.rb +607 -0
- data/lib/model/the_record.rb +266 -0
- data/lib/model/vertex.rb +236 -0
- data/lib/orientdb_private.rb +48 -0
- data/lib/other.rb +371 -0
- data/lib/railtie.rb +68 -0
- data/lib/rest/change.rb +147 -0
- data/lib/rest/create.rb +279 -0
- data/lib/rest/delete.rb +134 -0
- data/lib/rest/operations.rb +211 -0
- data/lib/rest/read.rb +171 -0
- data/lib/rest/rest.rb +112 -0
- data/lib/rest_disabled.rb +24 -0
- data/lib/support/logging.rb +38 -0
- data/lib/support/orient.rb +196 -0
- data/lib/support/orientquery.rb +469 -0
- data/rails.md +154 -0
- data/rails/activeorient.rb +32 -0
- data/rails/config.yml +10 -0
- data/rails/connect.yml +17 -0
- metadata +65 -24
- data/active-orient-0.4.gem +0 -0
- data/active-orient-0.41.gem +0 -0
- data/lib/model.rb +0 -468
- data/lib/orient.rb +0 -98
- data/lib/query.rb +0 -88
- data/lib/rest.rb +0 -1059
- data/lib/support.rb +0 -372
- data/test.rb +0 -4
- data/usecase.md +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7aeeeec320281d1ed65f73145b3d3008890c3ab46c480b480157cd2cd08dbace
|
4
|
+
data.tar.gz: 11d73a72a7510e5e6d8c93677504923141e78dd192ede941e4a042d4225f8dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c88ddae001fbdfbeba888d579235eb84d579f5e61c53591e4ef5cd1802a47c41f9e40d929c6f294a6b11a44f777ea41eb5b8f598342c15d72a2654eb273fc0d2
|
7
|
+
data.tar.gz: '0984f9cb17fe34c58047ad1e1144786f17bc5a760e2df883c4a9c8588eebd73cba7933b80d6c4a681c00927a791e986ca99303ae8fb9178c6705c652342b1842'
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
|
-
gem 'activesupport' , "~>4.2"
|
4
|
-
gem 'activemodel'
|
5
|
-
gem '
|
6
|
-
gem '
|
3
|
+
gem 'activesupport' # , "~>4.2"
|
4
|
+
gem 'activemodel' #, "~>4.2"
|
5
|
+
#gem 'activemodel-serializers-xml'
|
6
|
+
gem 'rest-client' , :git => 'https://github.com/rest-client/rest-client.git'
|
7
|
+
#gem 'nokogiri', '~> 1.6.6' #, :git => 'git://github.com/sparklemotion/nokogiri.git'
|
8
|
+
#gem 'orientdb' , :path => '/home/topo/orientdb-jruby' , :platforms => :jruby
|
9
|
+
gem 'sdoc'
|
10
|
+
#gem 'orientdb' , :git => 'git://github.com/topofocus/orientdb-jruby.git', :branch => '2.1.2', :platforms => :jruby
|
7
11
|
group :development, :test do
|
12
|
+
gem "awesome_print"
|
8
13
|
gem "rspec"
|
14
|
+
gem 'rspec-legacy_formatters'
|
9
15
|
gem 'rspec-its'
|
16
|
+
gem 'rspec-given'
|
10
17
|
gem 'rspec-collection_matchers'
|
11
18
|
gem 'rspec-context-private'
|
12
|
-
gem 'guard'
|
19
|
+
# gem 'guard-jruby-rspec', :platforms => :jruby, :git => 'git://github.com/jkutner/guard-jruby-rspec.git'
|
20
|
+
gem 'guard'#, :platforms => :ruby
|
13
21
|
gem 'guard-rspec'
|
14
22
|
## gem 'database_cleaner'
|
15
23
|
gem 'rb-inotify'
|
data/Guardfile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
|
-
|
4
|
-
guard :rspec, cmd: "bundle exec rspec" do
|
3
|
+
def fire
|
5
4
|
require "ostruct"
|
6
5
|
|
7
6
|
# Generic Ruby apps
|
@@ -12,10 +11,19 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
12
11
|
|
13
12
|
|
14
13
|
watch(%r{^spec/.+_spec\.rb$})
|
15
|
-
watch(%r{^spec/usecase/(.+)
|
14
|
+
# watch(%r{^spec/usecase/(.+)\.rb$})
|
16
15
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
16
|
+
# watch(%r{^examples/time_graph/spec/(.+)_spec\.rb$})
|
17
|
+
watch('examples/time_graph/spec/create_time_spec.rb')
|
17
18
|
watch('spec/spec_helper.rb') { "spec" }
|
18
19
|
|
19
|
-
watch(%r{^spec/support/(.+)\.rb$})
|
20
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
20
21
|
end
|
21
22
|
|
23
|
+
|
24
|
+
interactor :simple
|
25
|
+
if RUBY_PLATFORM == 'java'
|
26
|
+
guard( 'jruby-rspec') {fire} #', :spec_paths => ["spec"]
|
27
|
+
else
|
28
|
+
guard( :rspec, cmd: "bundle exec rspec") { fire }
|
29
|
+
end
|
data/README.md
CHANGED
@@ -1,325 +1,112 @@
|
|
1
1
|
# ActiveOrient
|
2
2
|
Use OrientDB to persistently store dynamic Ruby-Objects and use database queries to manage even very large
|
3
|
-
datasets.
|
3
|
+
datasets. **OrientDB Version 3 is required**
|
4
4
|
|
5
|
-
|
5
|
+
For changes from Version OrientDB 2.2 -> [Wiki](../..//wiki/Changes-2.2--to------3.0)
|
6
|
+
### Quick Start
|
6
7
|
|
8
|
+
You need a ruby 2.5/2.6 Installation and a working OrientDB-Instance (Version 3.0.17 or above).
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
- clone the project,
|
11
|
+
- run bundle install ; bundle update,
|
12
|
+
- update config/connect.yml,
|
13
|
+
- create the documentation:
|
14
|
+
```
|
15
|
+
sdoc . -w2 -x spec -x example
|
16
|
+
```
|
17
|
+
and point the browser to ~/active-orient/doc/index.htm
|
18
|
+
|
19
|
+
- read the [Wiki](./../../wiki/Initialisation)
|
20
|
+
- and start an irb-session by calling
|
16
21
|
```
|
17
|
-
|
18
|
-
|
19
|
-
Assuming, the server is located on localhost, we just define »default-server«
|
20
|
-
```ruby
|
21
|
-
ActiveOrient::OrientDB.default_server= { user: 'your user', password: 'your password' }
|
22
|
-
|
23
|
-
|
24
|
-
r = ActiveOrient::OrientDB.new database: 'First'
|
25
|
-
=> I, [2015-08-18T09:49:18.858758 #88831] INFO -- OrientDB#Connect: Connected to database First
|
26
|
-
=> #<ActiveOrient::OrientDB:0x000000048d0488 @res=#<RestClient::Resource:0x00000004927288
|
27
|
-
@url="http://localhost:2480", @block=nil,
|
28
|
-
@options={:user=>"xx", :password=>"***"}>, @database="First", @classes=[]>
|
22
|
+
cd bin
|
23
|
+
./active-orient-console t)est # or d)develpoment, p)roduction environment as defined in config/connect.ym
|
29
24
|
```
|
30
25
|
|
31
|
-
|
26
|
+
### Philosophy
|
32
27
|
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
M = r.open_class 'classname' #
|
38
|
-
M = r.create_class 'classname' # creates or opens a basic document-class
|
39
|
-
M = r.create_vertex_class 'classname' # creates or opens a vertex-class
|
40
|
-
M = r.create_edge_class 'classname' # creates or opens an edge-class, providing bidirectional links between documents
|
29
|
+
OrientDB is basicly an Object-Database. It shares the concept of Inheritance with OO-Languages, like Ruby.
|
30
|
+
|
31
|
+
Upon initialisation `ActiveOrient`reads the complete structure of the database, creates corresponding ruby-classes (including inheritance) and then loads user defined methods from the `Model Directory`. A separate schema definition is not neccessary.
|
41
32
|
|
42
|
-
|
43
|
-
```
|
33
|
+
`ActiveOrient`queries the OrientDB-Database, provides a cache to speed things up and provides handy methods to simplify the work with OrientDB. Like Active-Record it represents the "M" Part of the MCV-Design-Pattern. There is explicit Namespace support. Its philosophie resembles the [Hanami Project](https://github.com/hanami/hanami).
|
44
34
|
|
45
35
|
|
46
|
-
»M« is the ActiveOrient::Model-Class itself, a constant pointing to the class-definition of the ruby-class.
|
47
|
-
Its a shortcut for »ActiveOrient::Model::{Classname} and is reused if defined elsewhere.
|
48
36
|
|
49
|
-
If a schema is used, properties can be created and retrieved as well
|
50
|
-
```ruby
|
51
|
-
r.create_properties( M ) do
|
52
|
-
{ symbol: { propertyType: 'STRING' },
|
53
|
-
con_id: { propertyType: 'INTEGER' },
|
54
|
-
details: { propertyType: 'LINK', linkedClass: 'Contracts' }
|
55
|
-
}
|
56
37
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
38
|
+
#### CRUD
|
39
|
+
The CRUD-Process (create, read = query, update and remove) is performed as
|
40
|
+
```ruby
|
41
|
+
# create the class
|
42
|
+
ORD.create_class :m
|
43
|
+
# create a record
|
44
|
+
M.create name: 'Hugo', age: 46, interests: [ 'swimming', 'biking', 'reading' ]
|
45
|
+
# query the database
|
46
|
+
hugo = M.where( name: 'Hugo' ).first
|
47
|
+
# update the dataset
|
48
|
+
hugo.update father: M.create( name: "Volker", age: 76 ) # we create an internal link
|
49
|
+
hugo.father.name # --> volker
|
50
|
+
# change array elements
|
51
|
+
hugo.interests << "dancing" # --> [ 'swimming', 'biking', 'reading', 'dancing' ]
|
52
|
+
M.remove hugo
|
53
|
+
M.delete_class # removes the class from OrientDB and deletes the ruby-object-definition
|
64
54
|
```
|
55
|
+
|
65
56
|
|
66
57
|
#### Active Model interface
|
67
|
-
|
68
|
-
Every OrientDB-Database-Class is mirrord as Ruby-Class. The Class itself is defined by
|
69
|
-
```ruby
|
70
|
-
M = r.create_class 'classname'
|
71
|
-
M = r.create_class { superclass_name: 'classname' }
|
72
|
-
Vertex = r.create_vertex_class 'classname'
|
73
|
-
Edge = r.create_edge_class 'classname'
|
74
|
-
```
|
75
|
-
and is of TYPE ActiveOrient::Model::{classname}
|
76
58
|
|
77
|
-
As for ActiveRecord-Tables, the
|
59
|
+
As for ActiveRecord-Tables, the Model-class itself provides methods to inspect and filter datasets form the database.
|
78
60
|
|
79
61
|
```ruby
|
80
62
|
M.all
|
81
63
|
M.first
|
82
64
|
M.last
|
83
|
-
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
M.where town: 'Berlin'
|
87
|
-
```
|
88
|
-
performs a query on the class and returns the result as Array
|
65
|
+
M.where town: 'Berlin'
|
66
|
+
M.like "name = G*"
|
89
67
|
|
90
|
-
```ruby
|
91
68
|
M.count where: { town: 'Berlin' }
|
92
69
|
```
|
93
|
-
gets the number of datasets
|
94
|
-
SQL-Query in Orientdb can be provided to the count, where, first and last-method.
|
70
|
+
»count« gets the number of datasets fulfilling the search-criteria. Any parameter defining a valid SQL-Query in Orientdb can be provided to the »count«, »where«, »first« and »last«-method.
|
95
71
|
|
96
|
-
A »normal« Query is submitted via
|
72
|
+
A »normal« Query is submitted via
|
97
73
|
```ruby
|
98
|
-
M.
|
99
|
-
distinct: { some parameters }
|
100
|
-
where: { where-parameter }
|
101
|
-
order: { sorting-parameters }
|
102
|
-
group_by: { one grouping-parameter}
|
103
|
-
unwind:
|
104
|
-
skip:
|
105
|
-
limit:
|
74
|
+
M.get_records projection: { projection-parameter },
|
75
|
+
distinct: { some parameters },
|
76
|
+
where: { where-parameter },
|
77
|
+
order: { sorting-parameters },
|
78
|
+
group_by: { one grouping-parameter},
|
79
|
+
unwind: ,
|
80
|
+
skip: ,
|
81
|
+
limit:
|
106
82
|
|
107
83
|
# or
|
108
|
-
query = OrientSupport::OrientQuery.new {paramter}
|
109
|
-
M.
|
84
|
+
query = OrientSupport::OrientQuery.new {paramter}
|
85
|
+
M.query_database query
|
110
86
|
|
111
87
|
```
|
112
88
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
89
|
+
To update several records, a class-method »update_all« is defined.
|
117
90
|
```ruby
|
118
|
-
|
119
|
-
|
120
|
-
Edge.create_edge attributes: { :birthday => Date.today }, from: vertex_1, to: vertex_2
|
91
|
+
M.update_all connected: false # add a property »connected» to each record
|
92
|
+
M.update_all set:{ connected: true }, where: "symbol containsText 'S'"
|
121
93
|
```
|
122
|
-
connects the vertices and assigns the attributes to the edge
|
123
|
-
|
124
|
-
|
125
|
-
#### Links
|
126
|
-
|
127
|
-
A record in a database-class is defined by a »rid«. Every Model-Object comes with a handy »link«-method.
|
128
|
-
|
129
|
-
In OrientDB links are used to realise unidirectional 1:1 and 1:n relationships.
|
130
94
|
|
131
|
-
|
132
|
-
if an Object is stored in Cluster 30 and id 2, then "#30:2" fully qualifies the ActiveOrient::Model object.
|
95
|
+
Graph-support:
|
133
96
|
|
134
97
|
```ruby
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
```
|
141
|
-
base_document.single_link just contains the rid. When accessed, the ActiveOrient::Model::Testlinkclass-object is autoloaded and
|
142
|
-
``` ruby
|
143
|
-
base_document.single_link.att
|
98
|
+
ORD.create_vertex_class :the_vertex
|
99
|
+
ORD.create_edge_class :the_edge
|
100
|
+
vertex_1 = TheVertex.create color: "blue"
|
101
|
+
vertex_2 = TheVertex.create flower: "rose"
|
102
|
+
TheEdge.create_edge attributes: {:birthday => Date.today }, from: vertex_1, to: vertex_2
|
144
103
|
```
|
145
|
-
|
146
|
-
|
147
|
-
To store a list of links to other Database-Objects a simple Array is allocated
|
148
|
-
``` ruby
|
149
|
-
# predefined linkmap-properties
|
150
|
-
base_document = TestBase.create links: []
|
151
|
-
( 0 .. 20 ).each{ |y| base_document.links << TestLinks.create nr: y }
|
152
|
-
end
|
153
|
-
#or in schemaless-mode
|
154
|
-
base_document = TestBase.create links: (0..20).map{|y| TestLinks.create nr: y }
|
104
|
+
It connects the vertices and assigns the attributes to the edge.
|
155
105
|
|
106
|
+
To query a graph, SQL-like-Queries and Match-statements can be used (see below).
|
156
107
|
|
157
|
-
|
158
|
-
base_document.links behaves like a ruby-array.
|
159
|
-
|
160
|
-
If you got an undirectional graph
|
108
|
+
#### Other Documents
|
161
109
|
|
162
|
-
|
110
|
+
- [Rails 5-Integration](./rails.md)
|
163
111
|
|
164
|
-
the graphelements can be explored by joining the objects ( a.b.c.d ), or (a.b[5].c[9].d )
|
165
112
|
|
166
|
-
#### Edges
|
167
|
-
|
168
|
-
Edges are easily handled
|
169
|
-
```ruby
|
170
|
-
Vertex = r.create_vertex_class 'd1'
|
171
|
-
Eedge = r.create_edge_class 'e1'
|
172
|
-
|
173
|
-
start = Vertex.create something: 'nice'
|
174
|
-
the_end = Vertex.create something: 'not_nice'
|
175
|
-
the_edge = Edge.create_edge attributes: { transform_to: 'very bad' },
|
176
|
-
from: start,
|
177
|
-
to: the_end
|
178
|
-
|
179
|
-
(...)
|
180
|
-
the_edge.delete
|
181
|
-
```
|
182
|
-
|
183
|
-
There is a basic support for traversals throught a graph.
|
184
|
-
The Edges are accessed by their names (downcase).
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
start.e1[0]
|
188
|
-
--> #<ActiveOrient::Model::E1:0x000000041e4e30
|
189
|
-
@metadata={"type"=>"d", "class"=>"E1", "version"=>60, "fieldTypes"=>"out=x,in=x",
|
190
|
-
"cluster"=>16, "record"=>43},
|
191
|
-
@attributes={"out"=>"#31:23", "in"=>"#31:15", "transform_to"=>"very bad" }>
|
192
|
-
```
|
193
|
-
The Attributes "in" and "out" can be used to move across the graph
|
194
|
-
```ruby
|
195
|
-
start.e1[0].out.something
|
196
|
-
---> "not_nice
|
197
|
-
start.e1[0].in.something
|
198
|
-
---> "nice
|
199
|
-
```
|
200
|
-
#### Queries
|
201
|
-
Contrary to traditional SQL-based Databases OrientDB handles subqueries very efficient.
|
202
|
-
In addition, OrientDB supports precompiled statements (let-Blocks).
|
203
|
-
|
204
|
-
ActiveOrient is equipped with a simple QueryGenerator: ActiveSupport::OrientQuery.
|
205
|
-
It works in two modi: a comprehensive and a subsequent one
|
206
|
-
```ruby
|
207
|
-
|
208
|
-
q = OrientSupport::OrientQuery.new
|
209
|
-
q.from = Vertex
|
210
|
-
q.where << a: 2
|
211
|
-
q.where << 'b > 3 '
|
212
|
-
q.distinct = :profession
|
213
|
-
q.order = { :name => :asc }
|
214
|
-
|
215
|
-
```
|
216
|
-
is equivalent to
|
217
|
-
```ruby
|
218
|
-
q = OrientSupport::OrientQuery.new from: Vertex ,
|
219
|
-
where: [{ a: 2 }, 'b > 3 '],
|
220
|
-
distinct: :profession,
|
221
|
-
order: { :name => :asc }
|
222
|
-
q.to_s
|
223
|
-
=> select distinct( profession ) from Vertex where a = 2 and b > 3 order by name asc
|
224
|
-
```
|
225
|
-
Both modes can be mixed.
|
226
|
-
|
227
|
-
If subqueries are nessesary, they can be introduced as OrientSupport::OrientQuery or as »let-block«.
|
228
|
-
```ruby
|
229
|
-
q = OrientSupport::OrientQuery.new from: 'ModelQuery'
|
230
|
-
q.let << "$city = adress.city"
|
231
|
-
q.where = "$city.country.name = 'Italy' OR $city.country.name = 'France'"
|
232
|
-
q.to_s
|
233
|
-
=> select from ModelQuery let $city = adress.city where $city.country.name = 'Italy' OR $city.country.name = 'France'
|
234
|
-
```
|
235
|
-
or
|
236
|
-
```ruby
|
237
|
-
q = OrientSupport::OrientQuery.new
|
238
|
-
q.let << { a: OrientSupport::OrientQuery.new( from: '#5:0' ) }
|
239
|
-
q.let << { b: OrientSupport::OrientQuery.new( from: '#5:1' ) }
|
240
|
-
q.let << '$c= UNIONALL($a,$b) '
|
241
|
-
q.projection << 'expand( $c )'
|
242
|
-
q.to_s
|
243
|
-
=> select expand( $c ) let $a = ( select from #5:0 ), $b = ( select from #5:1 ), $c= UNIONALL($a,$b)
|
244
|
-
```
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
#### Execute SQL-Commands
|
250
|
-
Sql-commands can be executed as batch
|
251
|
-
|
252
|
-
The ActiveOrient::Query-Class provides a Query-Stack and an Records-Array which keeps the results.
|
253
|
-
The ActiveOrient::Query-Class acts as Parent-Class for aggregated Records (without a @rid), which are ActiveOrient::Model::Myquery Objects. If a Query returns a database-record, the correct ActiveOrient::Model-Class is instantiated.
|
254
|
-
|
255
|
-
```ruby
|
256
|
-
ach = ActiveOrient::Query.new
|
257
|
-
|
258
|
-
ach.queries << 'create class Contracts ABSTRACT'
|
259
|
-
ach.queries << 'create property Contracts.subcategory link'
|
260
|
-
ach.queries << 'create property Contracts.details link'
|
261
|
-
ach.queries << 'create class Stocks extends Contracts'
|
262
|
-
ach.queries << 'create class Futures extends Contracts'
|
263
|
-
result = ach.execute_queries transaction: false
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
```
|
268
|
-
queries the database as demonstrated above. In addition, the generated query itself is added to the »queries«-Stack and the result can be found in sample_query.records.
|
269
|
-
|
270
|
-
This feature can be used as a substitute for simple functions
|
271
|
-
|
272
|
-
```ruby
|
273
|
-
roq = ActiveOrient::Query.new
|
274
|
-
roq.queries =["select name, categories.subcategories.contracts from Industries where name containstext …'ial'"]
|
275
|
-
roq.execute_queries.each{|x| puts x.name, x.categories.inspect }
|
276
|
-
--> Basic Materials [["#21:1"]]
|
277
|
-
--> Financial [["#21:2"]]
|
278
|
-
--> Industrial [["#23:0", "#23:1"]]
|
279
|
-
```
|
280
|
-
|
281
|
-
OrientDB supports the execution of SQL-Batch-Commands.
|
282
|
-
( http://orientdb.com/docs/2.0/orientdb.wiki/SQL-batch.html )
|
283
|
-
This is supported simply by using a Array as Argument for ActiveOrient::Query.queries
|
284
|
-
|
285
|
-
Therefor complex queries can be simplified using database-variables
|
286
|
-
```ruby
|
287
|
-
ach = ActiveOrient::Query.new
|
288
|
-
ach.queries << [ "select expand( contracts ) from Openinterest"
|
289
|
-
"let con = select expand( contracts ) from Openinterest; ",
|
290
|
-
"...", ... ]
|
291
|
-
result = ach.execute_queries
|
292
|
-
```
|
293
|
-
|
294
|
-
The contract-documents are accessible with
|
295
|
-
```ruby
|
296
|
-
r.get_document '21:1'
|
297
|
-
--><Stocks: con_id: 77680640 currency: EUR details: #18:1 exchange: SMART local_symbol: BAS
|
298
|
-
primary_exchange: IBIS subcategory: #14:1 symbol: BAS>
|
299
|
-
```
|
300
|
-
or
|
301
|
-
```ruby
|
302
|
-
my_query = ActiveOrient::Query.new
|
303
|
-
['Contracts', 'Industries', 'Categories', 'Subcategories'].each do |table|
|
304
|
-
my_query.queries = [ "select count(*) from #{table}"]
|
305
|
-
|
306
|
-
count = my_query.execute_queries
|
307
|
-
# count=> [#<ActiveOrient::Model::Myquery:0x00000003b317c8
|
308
|
-
# @metadata={"type"=>"d", "class"=>nil, "version"=>0, "fieldTypes"=>"count=l"},
|
309
|
-
# @attributes={"count"=>4 } ] --> an Array with one Element, therefor count.pop
|
310
|
-
puts "Table #{table} \t #{count.pop.count} Datasets "
|
311
|
-
end
|
312
|
-
-->Table Contracts 56 Datasets
|
313
|
-
-->Table Industries 8 Datasets
|
314
|
-
-->Table Categories 22 Datasets
|
315
|
-
-->Table Subcategories 35 Datasets
|
316
|
-
|
317
|
-
```
|
318
|
-
|
319
|
-
Note that the fetched Object is of type »Stocks« (ActiveOrient::Model::Stocks).
|
320
|
-
|
321
|
-
The ActiveOrient-API documentation can be found here: https://github.com/orientechnologies/orientdb-docs/wiki/OrientDB-ActiveOrient
|
322
|
-
and the ActiveModel-documentation is here: http://www.rubydoc.info/gems/activemodel
|
323
|
-
|
324
|
-
|
325
|
-
|