orientdb-binary 0.7.1 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0dbc1ea16b695c940e53c9bfc8a806bff16c2ca
4
- data.tar.gz: fbf2bf494cbd6fb478018af6114d5ba657a3dfcf
3
+ metadata.gz: 988aa38dedf3895ac5a72eb6c2fd68b50b112f6d
4
+ data.tar.gz: 39c85446e40a94648491c6cd5c6182326413d80c
5
5
  SHA512:
6
- metadata.gz: d5eccede9b6aba253166a44f9ed7d5199df346f6a49db527bbc8be132ed6347a9303ae690857787de3fafb1094e4c3b45aba2bc7f8b3e28a713f2138453165dc
7
- data.tar.gz: 445f4cb0cd0cda17007e85209a65ea3767846df28ac7a6d347f675872c8233f8ce36ba6042739d363196b7b36a1b1321147183672f8a39f20091aeb6b6ffc725
6
+ metadata.gz: 4bb5ad2d394629ec76db3488d0f36e7dacae43f7441705d65c6ede2ae9cf75bb62c7d27e79c14ba591d8b7f67da3d7399961cc09c734d2dfed2509aa6fef83d1
7
+ data.tar.gz: b6b0484860ae2b328e46b010bb11a565ccbe2c0278da607cd4f7ba38f13819f0a9d383e1a7e8944c05b6cb29bc271e18765da2b16218e721b2cac98230b45a63
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orientdb-binary (0.7.0)
4
+ orientdb-binary (0.8.0)
5
5
  bindata (~> 1.8)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  module OrientdbBinary
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  NAME = "OrientDB Binary Protocol Ruby Client"
4
4
  PROTOCOL_VERSION = 20
5
5
  end
@@ -26,24 +26,6 @@ module OrientdbBinary
26
26
  _command(q.to_binary_s, class_name)
27
27
  end
28
28
 
29
- # def command(text)
30
- # mode = 's'.ord
31
- # class_name = 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'
32
- # fetchplan = "*0"
33
-
34
- # query = OrientdbBinary::Protocols::SqlCommandPayload.new text: text, non_text_limit: -1, fetchplan: fetchplan
35
- # p query
36
-
37
- # # command = OrientdbBinary::Protocols::Command.new session: session, mode: mode, clazz_name: class_name, command_payload_length: query.to_binary_s.length, command_payload: query.to_binary_s
38
- # command = OrientdbBinary::Protocols::Command.new session: session, mode: mode, text: text, command_payload: query.to_binary_s
39
- # command.write(socket)
40
-
41
- # status = BinData::Int8.read(socket).to_i
42
- # process_errors(status)
43
-
44
- # p OrientdbBinary::Protocols::CommandAnswer.read(socket)
45
- # end
46
-
47
29
  private
48
30
  def _command(binary_query, class_name)
49
31
  mode = 's'.ord
@@ -34,7 +34,9 @@ module OrientdbBinary
34
34
  }
35
35
  options = defaults.merge(args)
36
36
  answer = OrientdbBinary::Protocols::RecordLoad.new(params(options)).process(socket)
37
- answer.process(options)
37
+ unless answer[:exceptions]
38
+ answer.process(options)
39
+ end
38
40
  end
39
41
 
40
42
  # Create record from object
@@ -100,6 +102,22 @@ module OrientdbBinary
100
102
  def count_records
101
103
  OrientdbBinary::Protocols::DbCountRecords.new(params).process(socket)
102
104
  end
105
+
106
+ def register_script(opts)
107
+ default = {
108
+ :@class => "OFunction",
109
+ :@cluster => "ofunction",
110
+ language: "javascript",
111
+ parameters: [],
112
+ idempotent: nil,
113
+ code: nil,
114
+ name: nil
115
+ }
116
+
117
+ record = default.merge(opts)
118
+ create_record_from_object(record)
119
+ end
120
+
103
121
  end
104
122
  end
105
123
  end
@@ -5,7 +5,6 @@ module OrientdbBinary
5
5
 
6
6
  def process(socket)
7
7
  write(socket)
8
-
9
8
  status = BinData::Int8.read(socket).to_i
10
9
  errors = process_errors(socket, status)
11
10
  unless errors
@@ -4,7 +4,7 @@ module OrientdbBinary
4
4
  endian :big
5
5
 
6
6
  int32 :len, value: -> { data.length }
7
- string :data, read_length: :len
7
+ string :data, read_length: :len, onlyif: -> {len > -1}
8
8
 
9
9
  def get
10
10
  data
@@ -1,39 +1,6 @@
1
1
  module OrientdbBinary
2
2
  module Protocols
3
3
 
4
- # class SqlCommandPayload < BinData::Record
5
- # endian :big
6
-
7
- # protocol_string :text
8
- # int32 :non_text_limit
9
- # protocol_string :fetchplan
10
- # protocol_string :serialized_params, value: "params:[name:\"admin\"]"
11
- # end
12
-
13
- # class SqlCommandPayload < BinData::Record
14
- # endian :big
15
-
16
- # protocol_string :class_name
17
- # protocol_string :text
18
- # int32 :non_text_limit, value: -1
19
- # protocol_string :fetchplan, value: '*:-1'
20
- # protocol_string :serialized_params
21
- # # int8 :with_params, value: 1
22
- # # int8 :composite_key_params_present, value: 0
23
- # end
24
- class Recordd < BinData::Primitive
25
- endian :big
26
-
27
- array :records do
28
- int16 :marker
29
- int8 :record_type
30
- int16 :cluster_id
31
- int64 :position
32
- int32 :version
33
- protocol_string :record_content
34
- end
35
- end
36
-
37
4
  class SqlCommandPayload < BinData::Record
38
5
  endian :big
39
6
 
@@ -44,14 +11,36 @@ module OrientdbBinary
44
11
  protocol_string :serialized_params
45
12
  end
46
13
 
14
+ class ScriptCommandPayload < BinData::Record
15
+ endian :big
16
+
17
+ protocol_string :language
18
+ protocol_string :text
19
+ int32 :non_text_limit
20
+ protocol_string :fetchplan
21
+ int32 :serialized_params, value: 0
22
+ end
23
+
24
+ class Command < BinData::Record
25
+ include OrientdbBinary::Protocols::Base
26
+
27
+ endian :big
28
+
29
+ int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_COMMAND
30
+ int32 :session
31
+
32
+ bit8 :mode
33
+ protocol_string :command_payload
34
+ end
35
+
47
36
  class CommandAnswer < BinData::Record
48
37
  endian :big
49
38
 
50
39
  int32 :session
51
- int8 :synch_result_type
40
+ int8 :result_type
52
41
 
53
- int32 :collection_size, onlyif: -> {synch_result_type == 108}
54
- array :collection, initial_length: :collection_size, onlyif: -> {synch_result_type == 108} do
42
+ int32 :collection_size, onlyif: -> {result_type == 108}
43
+ array :collection, initial_length: -> {result_type == 114 ? 1 : collection_size}, onlyif: -> {result_type == 108 or result_type == 114} do
55
44
  int16 :marker
56
45
  int8 :record_type
57
46
  int16 :cluster_id
@@ -60,13 +49,6 @@ module OrientdbBinary
60
49
  protocol_string :record_content
61
50
  end
62
51
 
63
- int16 :marker, onlyif: -> {synch_result_type == 114}
64
- int8 :record_type, onlyif: -> {synch_result_type == 114}
65
- int16 :cluster_id, onlyif: -> {synch_result_type == 114}
66
- int64 :position, onlyif: -> {synch_result_type == 114}
67
- int32 :version, onlyif: -> {synch_result_type == 114}
68
- protocol_string :record_content, onlyif: -> {synch_result_type == 114 or synch_result_type == 97}
69
-
70
52
  array :prefetched_records, read_until: -> {element.payload_status == 0} do
71
53
  int8 :payload_status
72
54
  int16 :marker, onlyif: -> {payload_status > 0}
@@ -80,87 +62,6 @@ module OrientdbBinary
80
62
  end
81
63
 
82
64
 
83
- # class SqlCommandPayload < BinData::Record
84
- # endian :big
85
-
86
- # protocol_string :class_name, value: 'com.orientechnologies.orient.core.sql.OCommandSQL'
87
- # protocol_string :text, value: 'SELECT FROM OUser WHERE name = :name'
88
- # # protocol_string :fetchplan, value: '*:1'
89
- # int8 :with_params, value: 1
90
- # protocol_string :serialized_params, value: 'params:{"name":"admin"}'
91
- # int8 :composite_key_params_present, value: 0
92
- # end
93
-
94
- class ScriptCommandPayload < BinData::Record
95
- endian :big
96
-
97
- protocol_string :language
98
- protocol_string :text
99
- int32 :non_text_limit
100
- protocol_string :fetchplan
101
- int32 :serialized_params, value: 0
102
- end
103
-
104
- class Command < BinData::Record
105
- include OrientdbBinary::Protocols::Base
106
-
107
- endian :big
108
-
109
- int8 :operation, value: OrientdbBinary::OperationTypes::REQUEST_COMMAND
110
- int32 :session
111
65
 
112
- bit8 :mode
113
- protocol_string :command_payload
114
- end
115
-
116
- # class CommandAnswer < BinData::Record
117
- # endian :big
118
-
119
- # int32 :session
120
- # int8 :synch_result_type
121
- # int32 :collection_size
122
- # array :collection, initial_length: :collection_size do
123
- # int16 :marker
124
- # int8 :record_type
125
- # int16 :cluster_id
126
- # int64 :position
127
- # int32 :version
128
- # record_content :record_content
129
- # end
130
- # end
131
66
  end
132
67
  end
133
-
134
-
135
- # if ($this->mode == OrientDB::COMMAND_QUERY || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
136
- # $this->addByte(self::MODE_SYNC);
137
- # } else {
138
- # $this->addByte(self::MODE_ASYNC);
139
- # }
140
- # if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC) {
141
- # $objName = 'com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery';
142
- # } elseif ($this->mode == OrientDB::COMMAND_SELECT_SYNC) {
143
- # $objName = 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery';
144
- # } elseif ($this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
145
- # $objName = 'com.orientechnologies.orient.graph.gremlin.OCommandGremlin';
146
- # } else {
147
- # $objName = 'com.orientechnologies.orient.core.sql.OCommandSQL';
148
- # }
149
- # $buff = '';
150
- # // Java query object name serialization
151
- # $buff .= pack('N', strlen($objName));
152
- # $buff .= $objName;
153
- # // Query text serialization in TEXT mode
154
- # $buff .= pack('N', strlen($this->query));
155
- # $buff .= $this->query;
156
- # if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) {
157
- # // Limit set to -1 to ignore and use TEXT MODE
158
- # $buff .= pack('N', -1);
159
- # // Add a fetchplan
160
- # $buff .= pack('N', strlen($this->fetchPlan));
161
- # $buff .= $this->fetchPlan;
162
- # }
163
- # // Params serialization, we have 0 params
164
- # $buff .= pack('N', 0);
165
- # // Now query object serialization complete, add it to command bytes
166
- # $this->addString($buff);
@@ -0,0 +1,80 @@
1
+ module OrientdbBinary
2
+ module Serialization
3
+ class Serialize
4
+ def initialize()
5
+ end
6
+
7
+ def serialize_field_value(value)
8
+ result = ""
9
+ if value.is_a? String
10
+ return value if /^#\-{0,1}[\d]+:\-{0,1}[\d]+$/.match(value)
11
+ value = value.sub(/\\/, "\\\\")
12
+ value = value.gsub(/"/, "\\\"")
13
+ return "\"#{value}\""
14
+ end
15
+
16
+ if value.is_a? Integer
17
+ return value.to_s
18
+ end
19
+
20
+ if value.is_a? Float
21
+ return value.to_s + "f"
22
+ end
23
+
24
+ if value.is_a? Bignum
25
+ return value.to_s + "l"
26
+ end
27
+
28
+ if value.is_a? BigDecimal
29
+ return value.to_s + "d"
30
+ end
31
+
32
+ if value.is_a? Array or value.is_a? Set
33
+ type = value.class.to_s.downcase == "set" ? "<$>" : "[$]"
34
+ result = []
35
+
36
+ value.each do |el|
37
+ result << serialize_field_value(el)
38
+ end
39
+ return type.gsub("$", result.join(','))
40
+ end
41
+
42
+ if value.is_a?(TrueClass) or value.is_a?(FalseClass)
43
+ return value.to_s
44
+ end
45
+
46
+ if value.is_a? Hash
47
+ type = value[:type] == "d" ? "($)" : "{$}"
48
+ return type.gsub("$", serialize_document(value, value[:type] != "d"))
49
+ end
50
+
51
+ if value.is_a? Date
52
+ end
53
+
54
+ if value.is_a? DateTime
55
+ end
56
+
57
+ if value.is_a? Time
58
+ end
59
+ end
60
+
61
+ def serialize_document(document, is_map)
62
+ klass = "@"
63
+ result = []
64
+ document.each do |key, value|
65
+ unless [:version, :rid, :type].include? key
66
+ if key == :class
67
+ klass = value + "@"
68
+ else
69
+ field_wrap = is_map ? "\"" : ""
70
+ end
71
+ result << "#{field_wrap}#{key.to_s}#{field_wrap}:#{serialize_field_value(value)}"
72
+ end
73
+ end
74
+
75
+ return klass + "@" + result.join(',')
76
+ end
77
+ end
78
+ end
79
+ end
80
+
@@ -188,6 +188,62 @@ describe OrientdbBinary::Database do
188
188
  assert_equal 0, @db.load_record(cluster_id: 5, cluster_position: 0, fetch_plan: "*:-1", ignore_cache: 1, load_tombstones: 0)[:collection].length
189
189
  end
190
190
  end
191
+
192
+ describe "function" do
193
+ it "should be able to insert a function" do
194
+ record = @db.register_script(name: "test_script", code: "return 2;")
195
+ assert_equal "#7:0", record[:@rid]
196
+ end
197
+
198
+ end
199
+ end
200
+
201
+ describe "Queries" do
202
+
203
+ describe "Query" do
204
+ before do
205
+ @query = @db.query('SELECT FROM OUser where name = :name', {name: "admin"})
206
+ end
207
+
208
+ it "should find one data" do
209
+ assert_equal 1, @query[:collection].length
210
+ end
211
+
212
+ it "should be admin user" do
213
+ assert_equal 5, @query[:collection][0][:cluster_id]
214
+ assert_equal 0, @query[:collection][0][:position]
215
+ end
216
+ end
217
+
218
+ describe "Command" do
219
+ before do
220
+ @query = @db.command('INSERT INTO OUser (name, password, status) VALUES ("a", "secret", "ACTIVE"), ("b", "secret", "ACTIVE")', {})
221
+ end
222
+
223
+ it "should find one data" do
224
+ assert_equal 2, @query[:collection].length
225
+ end
226
+
227
+ it "should be user" do
228
+ user = OrientdbBinary::Parser::Deserializer.new.deserialize_document(@query[:collection][0][:record_content])
229
+ assert_equal "a", user[:name]
230
+ end
231
+ end
232
+
233
+ describe "Command returning one value" do
234
+ before do
235
+ @query = @db.command('INSERT INTO OUser (name, password, status) VALUES ("a", "secret", "ACTIVE")', {})
236
+ end
237
+
238
+ it "should find one data" do
239
+ assert_equal 1, @query[:collection].length
240
+ end
241
+
242
+ it "should be user" do
243
+ user = OrientdbBinary::Parser::Deserializer.new.deserialize_document(@query[:collection][0][:record_content])
244
+ assert_equal "a", user[:name]
245
+ end
246
+ end
191
247
  end
192
248
  end
193
249
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb-binary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Ostrowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-22 00:00:00.000000000 Z
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,6 +125,7 @@ files:
125
125
  - lib/orientdb_binary/protocols/record_update.rb
126
126
  - lib/orientdb_binary/protocols/shutdown.rb
127
127
  - lib/orientdb_binary/record_id.rb
128
+ - lib/orientdb_binary/serialization/serialize.rb
128
129
  - lib/orientdb_binary/server.rb
129
130
  - orientdb-binary.gemspec
130
131
  - test/database/test_database.rb