arcadedb 0.3.1 → 0.3.3
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 +4 -4
- data/.gitignore +57 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +168 -0
- data/Guardfile +30 -0
- data/LICENSE +21 -0
- data/README.md +242 -0
- data/Rakefile +11 -0
- data/arcade.yml +27 -0
- data/arcadedb.gemspec +35 -0
- data/bin/+ +106 -0
- data/bin/console +126 -0
- data/examples/books.rb +139 -0
- data/examples/relation_1__1.rb +149 -0
- data/examples/relation_1__n.rb +56 -0
- data/examples/relation_n_n.rb +194 -0
- data/lib/arcade/api/operations.rb +306 -0
- data/lib/arcade/api/version.rb +5 -0
- data/lib/arcade/base.rb +455 -0
- data/lib/arcade/database.rb +338 -0
- data/lib/arcade/errors.rb +71 -0
- data/lib/arcade/logging.rb +38 -0
- data/lib/arcade/version.rb +3 -0
- data/lib/arcade.rb +39 -0
- data/lib/config.rb +70 -0
- data/lib/init.rb +50 -0
- data/lib/match.rb +216 -0
- data/lib/model/basicdocument.rb +7 -0
- data/lib/model/basicedge.rb +6 -0
- data/lib/model/basicvertex.rb +6 -0
- data/lib/model/document.rb +10 -0
- data/lib/model/edge.rb +47 -0
- data/lib/model/vertex.rb +238 -0
- data/lib/models.rb +6 -0
- data/lib/query.rb +384 -0
- data/lib/support/class.rb +13 -0
- data/lib/support/conversions.rb +295 -0
- data/lib/support/model.rb +84 -0
- data/lib/support/object.rb +20 -0
- data/lib/support/sql.rb +74 -0
- data/lib/support/string.rb +116 -0
- data/rails/arcade.rb +20 -0
- data/rails/config.yml +10 -0
- data/rails/connect.yml +17 -0
- data/rails.md +147 -0
- metadata +49 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e052fea79d83b5cd35961dcc01af0ba617e80c3e0c26d058c5b69a3733a8edc
|
4
|
+
data.tar.gz: 92ef4c2900fee458959b01becf8fc2789fce5e87fb39e1cfc25b0f0df1e08d20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f74869fa3afe8f87250e94358b2b18a1fdcfdfa092ec0ef5a0293f970f1976b755463f070f0224aa276f4df3acd5555500d800b389c8463889347f8ef2d10ee7
|
7
|
+
data.tar.gz: a16c82bf62d9e30898de4e439a7fca37f470944cb92293fa11e4847146eac3a5c066447c1293d3fc73d1a078b348bdcdac21b44b10308ba9c10f141d793f17e2
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
# vim specific
|
13
|
+
*swp
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
# Ignore Byebug command history file.
|
18
|
+
.byebug_history
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
55
|
+
|
56
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
57
|
+
# .rubocop-https?--*
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## 0.3.1 - 2023-01-16
|
8
|
+
|
9
|
+
- Integration into the Bridgetown Environment
|
10
|
+
|
11
|
+
## 0.3.3 - 2023.04.23
|
12
|
+
- Support for embedded Dokuments and Maps
|
13
|
+
- iruby support
|
14
|
+
|
15
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
#git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
gemspec
|
7
|
+
gem 'sdoc'
|
8
|
+
gem 'dry-configurable'
|
9
|
+
gem 'pry'
|
10
|
+
#gem 'sequel'
|
11
|
+
|
12
|
+
#gem 'mini_sql' #, path: '../mini_sql/'
|
13
|
+
group :development, :test do
|
14
|
+
gem "awesome_print"
|
15
|
+
gem 'pastel'
|
16
|
+
gem 'zeitwerk'
|
17
|
+
gem 'terminal-table'
|
18
|
+
gem 'rubocop'
|
19
|
+
gem "rspec"
|
20
|
+
gem 'rspec-legacy_formatters'
|
21
|
+
gem 'rspec-its'
|
22
|
+
gem 'rspec-given'
|
23
|
+
gem 'rspec-collection_matchers'
|
24
|
+
gem 'rspec-context-private'
|
25
|
+
# gem 'guard-jruby-rspec', :platforms => :jruby, :git => 'git://github.com/jkutner/guard-jruby-rspec.git'
|
26
|
+
gem 'guard'#, :platforms => :ruby
|
27
|
+
gem 'guard-rspec'
|
28
|
+
gem 'rb-inotify'
|
29
|
+
gem 'pry'
|
30
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
arcadedb (0.3.2)
|
5
|
+
dry-core
|
6
|
+
dry-schema
|
7
|
+
dry-struct
|
8
|
+
typhoeus
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
ast (2.4.2)
|
14
|
+
awesome_print (1.9.2)
|
15
|
+
coderay (1.1.3)
|
16
|
+
concurrent-ruby (1.1.10)
|
17
|
+
diff-lcs (1.5.0)
|
18
|
+
dry-configurable (0.15.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
dry-core (~> 0.6)
|
21
|
+
dry-container (0.11.0)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
dry-core (0.7.1)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
dry-inflector (0.3.0)
|
26
|
+
dry-initializer (3.1.1)
|
27
|
+
dry-logic (1.2.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
dry-core (~> 0.5, >= 0.5)
|
30
|
+
dry-schema (1.10.6)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
33
|
+
dry-core (~> 0.5, >= 0.5)
|
34
|
+
dry-initializer (~> 3.0)
|
35
|
+
dry-logic (~> 1.2)
|
36
|
+
dry-types (~> 1.5)
|
37
|
+
dry-struct (1.4.0)
|
38
|
+
dry-core (~> 0.5, >= 0.5)
|
39
|
+
dry-types (~> 1.5)
|
40
|
+
ice_nine (~> 0.11)
|
41
|
+
dry-types (1.5.1)
|
42
|
+
concurrent-ruby (~> 1.0)
|
43
|
+
dry-container (~> 0.3)
|
44
|
+
dry-core (~> 0.5, >= 0.5)
|
45
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
46
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
47
|
+
ethon (0.16.0)
|
48
|
+
ffi (>= 1.15.0)
|
49
|
+
ffi (1.15.5)
|
50
|
+
formatador (1.1.0)
|
51
|
+
given_core (3.8.2)
|
52
|
+
sorcerer (>= 0.3.7)
|
53
|
+
guard (2.18.0)
|
54
|
+
formatador (>= 0.2.4)
|
55
|
+
listen (>= 2.7, < 4.0)
|
56
|
+
lumberjack (>= 1.0.12, < 2.0)
|
57
|
+
nenv (~> 0.1)
|
58
|
+
notiffany (~> 0.0)
|
59
|
+
pry (>= 0.13.0)
|
60
|
+
shellany (~> 0.0)
|
61
|
+
thor (>= 0.18.1)
|
62
|
+
guard-compat (1.2.1)
|
63
|
+
guard-rspec (4.7.3)
|
64
|
+
guard (~> 2.1)
|
65
|
+
guard-compat (~> 1.1)
|
66
|
+
rspec (>= 2.99.0, < 4.0)
|
67
|
+
ice_nine (0.11.2)
|
68
|
+
listen (3.7.1)
|
69
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
70
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
71
|
+
lumberjack (1.2.8)
|
72
|
+
method_source (1.0.0)
|
73
|
+
nenv (0.3.0)
|
74
|
+
notiffany (0.1.3)
|
75
|
+
nenv (~> 0.1)
|
76
|
+
shellany (~> 0.0)
|
77
|
+
parallel (1.22.1)
|
78
|
+
parser (3.1.2.0)
|
79
|
+
ast (~> 2.4.1)
|
80
|
+
pastel (0.8.0)
|
81
|
+
tty-color (~> 0.5)
|
82
|
+
pry (0.14.1)
|
83
|
+
coderay (~> 1.1)
|
84
|
+
method_source (~> 1.0)
|
85
|
+
rainbow (3.1.1)
|
86
|
+
rake (13.0.6)
|
87
|
+
rb-fsevent (0.11.1)
|
88
|
+
rb-inotify (0.10.1)
|
89
|
+
ffi (~> 1.0)
|
90
|
+
rdoc (6.3.3)
|
91
|
+
regexp_parser (2.4.0)
|
92
|
+
rexml (3.2.5)
|
93
|
+
rspec (3.11.0)
|
94
|
+
rspec-core (~> 3.11.0)
|
95
|
+
rspec-expectations (~> 3.11.0)
|
96
|
+
rspec-mocks (~> 3.11.0)
|
97
|
+
rspec-collection_matchers (1.2.0)
|
98
|
+
rspec-expectations (>= 2.99.0.beta1)
|
99
|
+
rspec-context-private (0.0.1)
|
100
|
+
rspec-core (3.11.0)
|
101
|
+
rspec-support (~> 3.11.0)
|
102
|
+
rspec-expectations (3.11.0)
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
+
rspec-support (~> 3.11.0)
|
105
|
+
rspec-given (3.8.2)
|
106
|
+
given_core (= 3.8.2)
|
107
|
+
rspec (>= 2.14.0)
|
108
|
+
rspec-its (1.3.0)
|
109
|
+
rspec-core (>= 3.0.0)
|
110
|
+
rspec-expectations (>= 3.0.0)
|
111
|
+
rspec-legacy_formatters (1.0.2)
|
112
|
+
rspec (~> 3.0)
|
113
|
+
rspec-mocks (3.11.1)
|
114
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
115
|
+
rspec-support (~> 3.11.0)
|
116
|
+
rspec-support (3.11.0)
|
117
|
+
rubocop (1.29.1)
|
118
|
+
parallel (~> 1.10)
|
119
|
+
parser (>= 3.1.0.0)
|
120
|
+
rainbow (>= 2.2.2, < 4.0)
|
121
|
+
regexp_parser (>= 1.8, < 3.0)
|
122
|
+
rexml (>= 3.2.5, < 4.0)
|
123
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
124
|
+
ruby-progressbar (~> 1.7)
|
125
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
126
|
+
rubocop-ast (1.18.0)
|
127
|
+
parser (>= 3.1.1.0)
|
128
|
+
ruby-progressbar (1.11.0)
|
129
|
+
sdoc (2.3.1)
|
130
|
+
rdoc (>= 5.0, < 6.4.0)
|
131
|
+
shellany (0.0.1)
|
132
|
+
sorcerer (2.0.1)
|
133
|
+
terminal-table (3.0.2)
|
134
|
+
unicode-display_width (>= 1.1.1, < 3)
|
135
|
+
thor (1.2.1)
|
136
|
+
tty-color (0.6.0)
|
137
|
+
typhoeus (1.4.0)
|
138
|
+
ethon (>= 0.9.0)
|
139
|
+
unicode-display_width (2.1.0)
|
140
|
+
zeitwerk (2.5.4)
|
141
|
+
|
142
|
+
PLATFORMS
|
143
|
+
x86_64-linux
|
144
|
+
|
145
|
+
DEPENDENCIES
|
146
|
+
arcadedb!
|
147
|
+
awesome_print
|
148
|
+
bundler (~> 2)
|
149
|
+
dry-configurable
|
150
|
+
guard
|
151
|
+
guard-rspec
|
152
|
+
pastel
|
153
|
+
pry
|
154
|
+
rake (~> 13.0)
|
155
|
+
rb-inotify
|
156
|
+
rspec
|
157
|
+
rspec-collection_matchers
|
158
|
+
rspec-context-private
|
159
|
+
rspec-given
|
160
|
+
rspec-its
|
161
|
+
rspec-legacy_formatters
|
162
|
+
rubocop
|
163
|
+
sdoc
|
164
|
+
terminal-table
|
165
|
+
zeitwerk
|
166
|
+
|
167
|
+
BUNDLED WITH
|
168
|
+
2.3.6
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
def fire
|
4
|
+
require "ostruct"
|
5
|
+
|
6
|
+
# Generic Ruby apps
|
7
|
+
rspec = OpenStruct.new
|
8
|
+
rspec.spec = ->(m) { "spec/#{m}_spec.rb" }
|
9
|
+
rspec.spec_dir = "spec"
|
10
|
+
rspec.spec_helper = "spec/spec_helper.rb"
|
11
|
+
|
12
|
+
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
# watch(%r{^spec/usecase/(.+)\.rb$})
|
15
|
+
watch(%r{^arcade/(.+)\.rb$}) { |m| "spec/arcade/#{m[1]}_spec.rb" }
|
16
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
17
|
+
# watch(%r{^examples/time_graph/spec/(.+)_spec\.rb$})
|
18
|
+
# watch('examples/time_graph/spec/create_time_spec.rb')
|
19
|
+
watch('spec/spec_helper.rb') { "spec" }
|
20
|
+
|
21
|
+
watch(%r{^spec/arcade/(.+)_spec\.rb$})
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
#interactor :simple
|
26
|
+
#if RUBY_PLATFORM == 'java'
|
27
|
+
#guard( 'jruby-rspec') {fire} #', :spec_paths => ["spec"]
|
28
|
+
#else
|
29
|
+
guard( :rspec, cmd: "bundle exec rspec --format documentation ") { fire }
|
30
|
+
#end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Hartmut Bischoff
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
# ArcadeDB
|
2
|
+
|
3
|
+
Ruby Interface to a [Arcade Database](https://arcadedb.com/).
|
4
|
+
|
5
|
+
The program utilizes the HTTP-JSON API to direct database queries to an ArcadeDB server.
|
6
|
+
The server's response is then mapped to an ORM (Object-Relational Mapping) based on DRY::Struct.
|
7
|
+
Each database type is represented by a dedicated Model Class, where complex queries are encapsulated.
|
8
|
+
The program also includes a Query-Preprocessor for constructing custom queries in ruby fashion.
|
9
|
+
|
10
|
+
***ArcadeDB internally uses `Arcade` as primary namespace****
|
11
|
+
|
12
|
+
## Prerequisites
|
13
|
+
|
14
|
+
A running AracdeDB-Instance. [Quick-Start-Guide](https://docs.arcadedb.com/#Quick-Start-Docker).
|
15
|
+
|
16
|
+
[ArcadeDB V 22.10.1](https://github.com/ArcadeData/arcadedb/releases/tag/22.10.1)ff is supported
|
17
|
+
|
18
|
+
## Config
|
19
|
+
|
20
|
+
Edit the file `arcade.yml` and provide suitable databases for test, development and production environment.
|
21
|
+
|
22
|
+
## Console
|
23
|
+
|
24
|
+
To start an interactive console, a script is provided in the bin-directory.
|
25
|
+
```
|
26
|
+
$ cd bin && ./console.rb t ( or "d" or "p" for Test, Development and Production environment)
|
27
|
+
|
28
|
+
**Database definitions (model-files) of the test-suite are included!**
|
29
|
+
```
|
30
|
+
|
31
|
+
## Examples & Specs
|
32
|
+
|
33
|
+
The `example` directory contains documented sample files for typical usecases
|
34
|
+
|
35
|
+
The `spec`-files in the rspec-test-suite-section are worth reading, too.
|
36
|
+
|
37
|
+
## Implementation
|
38
|
+
|
39
|
+
The adapter uses a 3 layer concept.
|
40
|
+
|
41
|
+
Top-Layer : `Arcade::Base`-Model-Objects.
|
42
|
+
They operate similar to ActiveRecord Model Objects but are based on [Dry-Struct](https://dry-rb.org/gems/dry-struct/1.0/).
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# Example model file /model/demo/user.rb
|
46
|
+
module Demo
|
47
|
+
class Person < Arcade::Vertex
|
48
|
+
attribute :name, Types::Nominal::String
|
49
|
+
timestamps true
|
50
|
+
|
51
|
+
def grandparents
|
52
|
+
db.query( "select in('is_family') from #{rid} ") &.allocate_model
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
__END__
|
57
|
+
CREATE PROPERTY demo_user.name STRING
|
58
|
+
CREATE INDEX on demo_user( name ) UNIQUE
|
59
|
+
```
|
60
|
+
|
61
|
+
Only the `name` attribute is declared. Timestamps (created & updated attributes) are included, too
|
62
|
+
|
63
|
+
`Demo::User.create_type` creates the type and executes the database-commands after __END__.
|
64
|
+
|
65
|
+
Other properties are schemaless.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
Person.create name: "Hubert", age: 35
|
69
|
+
Person.update set: { age: 36 }, where: { name: 'Hubert' }
|
70
|
+
persons = Person.where "age > 40"
|
71
|
+
persons.first.update age: 37
|
72
|
+
persons.first.update father: Person.create( name: 'Mike', age: 94 )
|
73
|
+
|
74
|
+
Person.all
|
75
|
+
Person.delete all: true || where: age: 56 , ...
|
76
|
+
```
|
77
|
+
|
78
|
+
A **Query Preprocessor** is implemented. Its adapted from ActiveOrient. The [documentation](https://github.com/topofocus/active-orient/wiki/OrientQuery)
|
79
|
+
is still valid, however the class has changed to `Arcade::Query`.
|
80
|
+
|
81
|
+
The **second Layer** handles Database-Requests.
|
82
|
+
In its actual implementation, these requests are delegated to the HTTP/JSON-API.
|
83
|
+
|
84
|
+
`Arcade::Init` uses the database specification of the `arcade.yml` file.
|
85
|
+
The database-handle is always present through `Arcade::Init.db`
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
DB = Arcade::Init.db
|
89
|
+
|
90
|
+
$ DB.get nn, mm # returns a Aracde:Base object
|
91
|
+
# rid is either "#11:10:" or two numbers
|
92
|
+
$ DB.query querystring # returns either an Array of results (as Hash)
|
93
|
+
$ DB.execute { querystring } #
|
94
|
+
$ DB.create <name>, attribute: value .... # Creates a new <Document | Vertex> and returns the rid
|
95
|
+
# Operation is performed as Database-Transaction and is rolled back on error
|
96
|
+
$ DB.insert <name>, attribute: value .... # Inserts a new <Document | Vertex> and returns the rid
|
97
|
+
$ DB.create_edge <name>, from: <rid> or [rid, rid, ..] , to: <rid> or [rid, rid, ..]
|
98
|
+
|
99
|
+
DB.query " Select from person where age > 40 "
|
100
|
+
DB.execute { " Update person set name='Hubert' return after $current where age = 36 " }
|
101
|
+
```
|
102
|
+
|
103
|
+
**Convert database input to Arcade::Base Models**
|
104
|
+
|
105
|
+
Either `DB.query` or `DB.execute` return the raw JSON-input from the database. It can always converted to model-objects by chaining
|
106
|
+
`allocatet_model`.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
$ DB.query "select from my_names limit 1"
|
110
|
+
# which is identical to
|
111
|
+
$ My::Names.query( limit: 1).query
|
112
|
+
=> [{:@out=>0, :@rid=>"#225:6", :@in=>0, :@type=>"my_names", :@cat=>"v", :name=>"Zaber"}]
|
113
|
+
# then
|
114
|
+
$ My::Names.query( limit: 1).query.allocate_model.to_human
|
115
|
+
=> ["<my_names[#225:6]: name: Zaber>" ]
|
116
|
+
# replaces the hash with a My::Names Object
|
117
|
+
```
|
118
|
+
|
119
|
+
The **Base Layer** implements a low level access to the database API.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
|
123
|
+
$ Arcade::Api.databases # returns an array of known databases
|
124
|
+
$ Arcade::Api.create_database <a string> # returns true if successfull
|
125
|
+
$ Arcade::Api.drop_database <a string> # returns true if successfull
|
126
|
+
|
127
|
+
$ Arcade::Api.begin_transaction <database>
|
128
|
+
$ Arcade::Api.create_document <database>, <type>, attribute: value , ...
|
129
|
+
$ Arcade::Api.execute( <database> ) { <query> }
|
130
|
+
$ Arcade::Api.commit <database> # or Arcade::Api.rollback
|
131
|
+
|
132
|
+
|
133
|
+
$ Arcade::Api.query( <database> ) { <query> }
|
134
|
+
$ Arcade::Api.get_record <database>, rid # returns a hash
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
`<query>` is either a string or a hash:
|
139
|
+
```ruby
|
140
|
+
{ :query => "<the query string> ",
|
141
|
+
:language => one of :sql, :cypher, :gmelin: :neo4 ,
|
142
|
+
:params => a hash of parameters,
|
143
|
+
:limit => a number ,
|
144
|
+
:serializer => one of :graph, :record }
|
145
|
+
```
|
146
|
+
|
147
|
+
## ORM Behavior
|
148
|
+
|
149
|
+
Simple tasks are implemented on the model layer.
|
150
|
+
|
151
|
+
### Ensure that a Record exists
|
152
|
+
|
153
|
+
The `upsert` command either updates or creates a database record.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
User.upsert name: 'Hugo'
|
157
|
+
# or
|
158
|
+
User.upsert set: { age: 46 }, where: { name: 'Hugo' }
|
159
|
+
```
|
160
|
+
either creates the record (and returns it) or returns the existing database entry. Obviously, the addressed attribute (where condition)
|
161
|
+
must have a proper index.
|
162
|
+
|
163
|
+
The `upsert` statement provides a smart method to ensure the presence of a defined starting point.
|
164
|
+
|
165
|
+
### Assign Nodes to a Vertex
|
166
|
+
|
167
|
+
Apart from accessing attributes by their method-name, adjacent edges and notes are fetched through
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
new_vertex = ->(n) { Node.create( note_count: n ) } ## lambda to create a Node type record
|
171
|
+
nucleus = BaseNode.create item: 'b' ## create a start node
|
172
|
+
(1..10).each{ |n| nucleus.assign( via: Connects, vertex: new_vertex[n]) } ## connect nodes via Connects-Edges
|
173
|
+
```
|
174
|
+
After creating a star-like structure, the environment can be explored
|
175
|
+
```ruby
|
176
|
+
nucleus.edges.to_human
|
177
|
+
=>["<connects[#80:14] :.: #4:0->{}->#34:2>",
|
178
|
+
"<connects[#79:13] :.: #4:0->{}->#31:1>",
|
179
|
+
( ... )
|
180
|
+
"<connects[#79:14] :.: #4:0->{}->#31:2>"]
|
181
|
+
|
182
|
+
nucleus.nodes.to_human
|
183
|
+
=> ["<node[#34:2]: item: 10>",
|
184
|
+
"<node[#31:1]: item: 1>",
|
185
|
+
( ... )
|
186
|
+
"<node[#31:2]: item: 9>"]
|
187
|
+
```
|
188
|
+
|
189
|
+
Edges provide a `vertices`-method to load connected ones. Both vertices and edges expose `in`, `out`, `both`-methods to select connections further.
|
190
|
+
Specific edge-classes (types) are provided with the `via:` parameter, as shown in `assign` above.
|
191
|
+
|
192
|
+
|
193
|
+
### Traverse Facility
|
194
|
+
|
195
|
+
To ease queries to the graph database, `Arcade::Query` supports traversal of nodes
|
196
|
+
|
197
|
+
Create a Chain of Nodes:
|
198
|
+
```ruby
|
199
|
+
|
200
|
+
def linear_elements start, count #returns the edge created
|
201
|
+
new_vertex = ->(n) { Arcade::ExtraNode.create( note_count: n ) }
|
202
|
+
(2..count).each{ |n| start = start.assign vertex: new_vertex[n], via: Arcade::Connects }
|
203
|
+
end
|
204
|
+
|
205
|
+
start_node = Arcade::ExtraNode.create( item: 'linear' )
|
206
|
+
linear_elements start_node , 200
|
207
|
+
```
|
208
|
+
|
209
|
+
Select a range of nodes and perform a mathematical operation
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
hundred_elements = start_node.traverse :out, via: Arcade::Connects, depth: 100
|
213
|
+
median = Query.new from: hundred_elements,
|
214
|
+
projection: 'median(note_count)',
|
215
|
+
where: '$depth>=50'
|
216
|
+
median.to_s
|
217
|
+
-=> select median(note_count) from ( traverse out(connects) from #52:0 while $depth < 100 ) where $depth>=50
|
218
|
+
=> {:"median(note_count)"=>75.5 }
|
219
|
+
```
|
220
|
+
## Include in your own project
|
221
|
+
|
222
|
+
Until a gem is released, first clone the project and set up your project environment
|
223
|
+
```
|
224
|
+
mkdir workspace && cd workspace
|
225
|
+
git clone https://github.com/topofocus/arcadedb
|
226
|
+
mkdir my-project && cd my-project
|
227
|
+
bundle init
|
228
|
+
cat "gem arcadedb, path='../arcadedb' " >> Gemfile
|
229
|
+
bundle install && bundle upate
|
230
|
+
cp ../arcadedb/config.yml .
|
231
|
+
mkdir bin
|
232
|
+
cp ../arcadedb/bin/console bin/
|
233
|
+
````
|
234
|
+
|
235
|
+
|
236
|
+
## Contributing
|
237
|
+
|
238
|
+
Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
239
|
+
|
240
|
+
## Code of Conduct
|
241
|
+
|
242
|
+
Everyone interacting in the Core project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/topofocus/arcadedb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/arcade.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
## absolute path to the oetl-script
|
3
|
+
:pg:
|
4
|
+
:host: 10.247.8.109 # hierdevel
|
5
|
+
:port: 5432
|
6
|
+
:environment:
|
7
|
+
:test:
|
8
|
+
dbname: playground
|
9
|
+
user: root
|
10
|
+
pass: topo1focus
|
11
|
+
:development:
|
12
|
+
dbname: devel
|
13
|
+
user: root
|
14
|
+
pass: topo1focus
|
15
|
+
:production:
|
16
|
+
dbname: production
|
17
|
+
user: root
|
18
|
+
pass: topo1focus
|
19
|
+
:admin:
|
20
|
+
:host: 10.247.8.109
|
21
|
+
:port: 2480
|
22
|
+
:user: root
|
23
|
+
:pass: topo1focus
|
24
|
+
:logger: stdout # 'file' or 'stdout'
|
25
|
+
:namespace: Arcade # Default Namespace
|
26
|
+
:autoload: true # load model if a link is detected in a record
|
27
|
+
|
data/arcadedb.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arcade/version'
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "arcadedb"
|
7
|
+
spec.version = Arcade::VERSION
|
8
|
+
spec.author = "Hartmut Bischoff"
|
9
|
+
spec.email = "topofocus@gmail.com"
|
10
|
+
spec.license = 'MIT'
|
11
|
+
spec.summary = %q{Ruby Interface to ArcadeDB}
|
12
|
+
spec.description = %q{Provides access to ArcadeDB from ruby}
|
13
|
+
spec.homepage = "https://github.com/topofocus/arcadedb"
|
14
|
+
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 2"
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 4.0"
|
26
|
+
# 'activesupport', '>= 6.0'
|
27
|
+
# spec.add_dependency 'activemodel'
|
28
|
+
spec.add_dependency "typhoeus"
|
29
|
+
spec.add_dependency 'dry-schema'
|
30
|
+
spec.add_dependency 'dry-struct'
|
31
|
+
spec.add_dependency 'dry-core'
|
32
|
+
## Database-Access via Postgres is not implemented
|
33
|
+
# spec.add_dependency 'pg'
|
34
|
+
# spec.add_dependency 'mini_sql'
|
35
|
+
end
|