datomic-client 0.3.0 → 0.4.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.
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/datomic-client.gemspec +1 -1
- data/lib/datomic/client.rb +7 -3
- data/lib/datomic/client/version.rb +1 -1
- data/spec/datomic_client_spec.rb +40 -20
- metadata +6 -6
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,8 +56,9 @@ Please report them [on github](http://github.com/cldwalker/datomic-client/issues
|
|
56
56
|
|
57
57
|
## Credits
|
58
58
|
|
59
|
-
* @crnixon for adding edn support
|
59
|
+
* @crnixon for adding edn support and improving #query
|
60
60
|
* @flyingmachine for starting this with me
|
61
|
+
* @relevance for fridays to work on this
|
61
62
|
|
62
63
|
## Links
|
63
64
|
|
data/datomic-client.gemspec
CHANGED
data/lib/datomic/client.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'datomic/client/version'
|
2
2
|
require 'datomic/client/response'
|
3
3
|
require 'rest-client'
|
4
|
-
require 'set' # Remove when fixed upstream
|
5
4
|
require 'edn'
|
6
5
|
|
7
6
|
module Datomic
|
@@ -54,9 +53,14 @@ module Datomic
|
|
54
53
|
end
|
55
54
|
|
56
55
|
# Query can be a ruby data structure or a string representing clojure data
|
57
|
-
|
56
|
+
# If the args_or_dbname is a String, it will be converted into one arg
|
57
|
+
# pointing to that database.
|
58
|
+
def query(query, args_or_dbname, params = {})
|
58
59
|
query = transmute_data(query)
|
59
|
-
args =
|
60
|
+
args = args_or_dbname.is_a?(String) ?
|
61
|
+
[{:"db/alias" => [@storage, args_or_dbname].join('/')}] :
|
62
|
+
args_or_dbname
|
63
|
+
args = transmute_data(args)
|
60
64
|
get root_url("api/query"), params.merge(:q => query, :args => args)
|
61
65
|
end
|
62
66
|
|
data/spec/datomic_client_spec.rb
CHANGED
@@ -4,8 +4,9 @@ require 'datomic/client'
|
|
4
4
|
# bin/rest 9000 socrates datomic:mem://
|
5
5
|
describe Datomic::Client do
|
6
6
|
let(:datomic_uri) { ENV['DATOMIC_URI'] || 'http://localhost:9000' }
|
7
|
+
let(:storage) { ENV['DATOMIC_STORAGE'] || 'socrates' }
|
7
8
|
let(:client) do
|
8
|
-
Datomic::Client.new datomic_uri,
|
9
|
+
Datomic::Client.new datomic_uri, storage
|
9
10
|
end
|
10
11
|
let(:schema) { File.read(File.expand_path('../fixtures/seattle-schema.dtm', __FILE__)) }
|
11
12
|
|
@@ -125,34 +126,53 @@ describe Datomic::Client do
|
|
125
126
|
end
|
126
127
|
|
127
128
|
describe "#query" do
|
129
|
+
let(:db_id) { 1 }
|
130
|
+
|
128
131
|
before {
|
129
132
|
client.create_database('test-query')
|
130
133
|
client.transact('test-query', schema)
|
131
|
-
client.transact('test-query', [
|
134
|
+
client.transact('test-query', [{:"db/id" => db_id, :"community/name" => "Some Community"}])
|
132
135
|
}
|
133
136
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
137
|
+
context "with a dbname passed in for args" do
|
138
|
+
it "returns a correct response with a string query" do
|
139
|
+
resp = client.query('[:find ?e :where [?e :community/name "Some Community"]]', 'test-query')
|
140
|
+
resp.code.should == 200
|
141
|
+
resp.data.should be_a(Array)
|
142
|
+
end
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
it "returns a correct response with limit param" do
|
145
|
+
resp = client.query('[:find ?c :where [?c :community/name]]', 'test-query', :limit => 0)
|
146
|
+
resp.code.should == 200
|
147
|
+
resp.data.should be_a(Array)
|
148
|
+
resp.data.should == []
|
149
|
+
end
|
147
150
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
it "returns a correct response with a data query" do
|
152
|
+
resp = client.query([:find, EDN::Type::Symbol.new('?c'), :where,
|
153
|
+
[EDN::Type::Symbol.new('?c'), :"community/name"]],
|
154
|
+
'test-query')
|
155
|
+
resp.code.should == 200
|
156
|
+
resp.data.should be_a(Array)
|
157
|
+
end
|
154
158
|
end
|
155
159
|
|
160
|
+
context "with an array passed in for args" do
|
161
|
+
it "returns a correct response" do
|
162
|
+
client.transact('test-query', [{
|
163
|
+
:"db/id" => db_id,
|
164
|
+
:"community/name" => "Some Community Again"}])
|
165
|
+
query = [:find, ~'?e', ~'?v', :where, [~'?e', :"community/name", ~'?v']]
|
166
|
+
|
167
|
+
resp_without_history = client.query(query, 'test-query')
|
168
|
+
resp_with_history = client.query(query, [{
|
169
|
+
:"db/alias" => "#{storage}/test-query",
|
170
|
+
:history => true}])
|
171
|
+
resp_with_history.code.should == 200
|
172
|
+
resp_with_history.data.should be_a(Array)
|
173
|
+
resp_with_history.data.count.should > resp_without_history.data.count
|
174
|
+
end
|
175
|
+
end
|
156
176
|
end
|
157
177
|
|
158
178
|
describe "#events" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datomic-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.9.
|
85
|
+
version: 0.9.4
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.9.
|
93
|
+
version: 0.9.4
|
94
94
|
description: This gem provides a simple way to use datomic's http API - http://docs.datomic.com/rest.html.
|
95
95
|
email: gabriel.horner@gmail.com
|
96
96
|
executables: []
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -555568115578253090
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
hash:
|
136
|
+
hash: -555568115578253090
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
139
|
rubygems_version: 1.8.24
|