datomic-client 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+ * query endpoint takes query arg first to match endpoint syntax
3
+ * query endpoint can a take user's args
4
+
1
5
  ## 0.3.0
2
6
  * Update to work for 0.8.3520 - makes breaking changes for previous APIs
3
7
  * Remove monitor method
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
 
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'rspec', '~> 2.11'
20
20
  s.add_development_dependency 'rake', '~> 0.9.2.2'
21
21
  s.add_dependency 'rest-client', '~> 1.6.7'
22
- s.add_dependency 'edn', '~> 0.9.1'
22
+ s.add_dependency 'edn', '~> 0.9.4'
23
23
  end
@@ -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
- def query(dbname, query, params = {})
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 = [{:"db/alias" => [@storage, dbname].join('/')}].to_edn
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
 
@@ -1,5 +1,5 @@
1
1
  module Datomic
2
2
  class Client
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -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, ENV['DATOMIC_STORAGE'] || 'socrates'
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', [[:"db/add", 1, :"community/name", "Some Community"]])
134
+ client.transact('test-query', [{:"db/id" => db_id, :"community/name" => "Some Community"}])
132
135
  }
133
136
 
134
- it "returns a correct response with a string query" do
135
- resp = client.query('test-query', '[:find ?c :where [?c :community/name]]')
136
- resp.code.should == 200
137
- resp.data.should be_a(Array)
138
- resp.data.should == [[1]]
139
- end
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
- it "returns a correct response with limit param" do
142
- resp = client.query('test-query', '[:find ?c :where [?c :community/name]]', :limit => 0)
143
- resp.code.should == 200
144
- resp.data.should be_a(Array)
145
- resp.data.should == []
146
- end
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
- it "returns a correct response with a data query" do
149
- resp = client.query('test-query',
150
- [:find, EDN::Type::Symbol.new('?c'), :where,
151
- [EDN::Type::Symbol.new('?c'), :"community/name"]])
152
- resp.code.should == 200
153
- resp.data.should be_a(Array)
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.3.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-14 00:00:00.000000000 Z
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.1
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.1
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: 2191169239501310737
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: 2191169239501310737
136
+ hash: -555568115578253090
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.24