diametric 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ describe Diametric::Persistence::Peer, :jruby do
21
21
  author.update(:books => [book])
22
22
  result = Diametric::Persistence::Peer.q("[:find ?e ?name ?books :in $ :where [?e :author/name ?name] [?e :author/books ?books]]", @conn.db)
23
23
  boo_dbid = result.first[2]
24
- boo = Author.from_dbid_or_entity(boo_dbid, @conn)
24
+ boo = Author.reify(boo_dbid, @conn)
25
25
  boo.title.should == "Candy"
26
26
  end
27
27
 
@@ -35,11 +35,12 @@ describe Diametric::Persistence::Peer, :jruby do
35
35
  author.update(:books => [book1, book2])
36
36
  result = Diametric::Persistence::Peer.q("[:find ?e ?name ?books :in $ :where [?e :author/name ?name] [?e :author/books ?books]]", @conn.db)
37
37
  result.size.should == 2
38
- boo_dbid = result[0][2]
39
- boo = Book.from_dbid_or_entity(boo_dbid, @conn)
38
+ result_in_array = result.to_a
39
+ boo_dbid = result_in_array[0][2]
40
+ boo = Book.reify(boo_dbid, @conn)
40
41
  boo.title.should match(/Honey|Chips/)
41
- foo_dbid = result[1][2]
42
- foo = Book.from_dbid_or_entity(boo_dbid, @conn)
42
+ foo_dbid = result_in_array[1][2]
43
+ foo = Book.reify(boo_dbid, @conn)
43
44
  foo.title.should match(/Honey|Chips/)
44
45
  end
45
46
 
@@ -58,19 +59,19 @@ describe Diametric::Persistence::Peer, :jruby do
58
59
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?name] :where [?e :author/name ?name]]", @conn.db, ["Ms. Wilber"])
59
60
  result.size.should == 1
60
61
  result.first.first.to_s.should == author1.dbid.to_s
61
- a = Author.from_dbid_or_entity(result.first.first, @conn)
62
+ a = Author.reify(result.first.first, @conn)
62
63
  a.books.size.should == 2
63
64
  a.books.each do |b|
64
- Author.from_dbid_or_entity(b, @conn).title.should match(/Pie|Donuts/)
65
+ Author.reify(b, @conn).title.should match(/Pie|Donuts/)
65
66
  end
66
67
 
67
68
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?title] :where [?e :book/title ?title]]", @conn.db, ["Pie"])
68
69
  result.size.should == 1
69
70
  result.first.first.to_s.should == book1.dbid.to_s
70
- b = Book.from_dbid_or_entity(result.first.first, @conn)
71
+ b = Book.reify(result.first.first, @conn)
71
72
  b.authors.size.should == 2
72
73
  b.authors.each do |a|
73
- Book.from_dbid_or_entity(a, @conn).name.should match(/Ms\.\sWilber|Mr\.\sSmith/)
74
+ Book.reify(a, @conn).name.should match(/Ms\.\sWilber|Mr\.\sSmith/)
74
75
  end
75
76
  end
76
77
  end
@@ -5,7 +5,9 @@ class Somebody
5
5
  include Diametric::Persistence::Peer
6
6
 
7
7
  attribute :name, String
8
- attribute :parent, Ref, :cardinality => :one
8
+ attribute :mom, Ref, :cardinality => :one
9
+ attribute :dad, Ref, :cardinality => :one
10
+ attribute :kids, Ref, :cardinality => :many
9
11
  end
10
12
 
11
13
  describe "RailsConf 2013", :jruby => true do
@@ -13,30 +15,33 @@ describe "RailsConf 2013", :jruby => true do
13
15
  before(:all) do
14
16
  datomic_uri = "datomic:mem://somebody-#{SecureRandom.uuid}"
15
17
  @conn = Diametric::Persistence::Peer.connect(datomic_uri)
18
+ Somebody.create_schema(@conn).get
16
19
  end
20
+
17
21
  after(:all) do
18
22
  @conn.release
19
23
  end
20
24
 
21
- it "should create schema" do
22
- binding.pry
23
- Sombody.create_schema(@conn)
24
- end
25
-
26
25
  it "should create instances" do
27
- alice = Somebody.new
28
- alice.name = "Alice Wonderland"
29
- alice.parent = ""
30
- yoko.save
26
+ mom = Somebody.new(name: "Snow White")
27
+ mom.save(@conn)
28
+ dad = Somebody.new(name: "Prince Brave")
29
+ dad.save(@conn)
31
30
  binding.pry
32
-
33
- clinton = Developer.new(:name => "Clinton N. Dreisbach", :friends => [yoko])
34
- clinton.save
31
+ Somebody.new(name: "Alice Wonderland", mom: mom, dad: dad).save(@conn)
35
32
  binding.pry
36
-
37
- ryan = Developer.new(:name => "Ryan Neufeld", :friends => [clinton, yoko])
38
- ryan.save
33
+ me = Diametric::Query.new(Somebody, @conn, true).where(name: "Alice Wonderland").first
34
+ binding.pry
35
+ puts "me: #{me.name}, me's mom: #{me.mom.name}, me's dad: #{me.dad.name}"
36
+ mario = Somebody.new(name: "Mario", mom: me)
37
+ mario.save
38
+ luigi = Somebody.new(name: "Luigi", mom: me)
39
+ luigi.save
40
+ me.update_attributes(kids: [mario, luigi])
41
+ me = Diametric::Query.new(Somebody, @conn, true).where(name: "Alice Wonderland").first
42
+ puts me.kids.inspect
39
43
  binding.pry
44
+ puts Somebody.reify(me.kids.first.mom).name
40
45
  end
41
46
  end
42
47
  end
@@ -18,28 +18,62 @@ describe Diametric::Entity, :integration => true, :jruby => true do
18
18
  end
19
19
 
20
20
  let(:query) { Diametric::Query.new(Penguin, @conn, true) }
21
+
21
22
  it "should update entity" do
22
- penguin = Penguin.new(:name => "Mary", :age => 2)
23
+ bday = DateTime.parse('2005-01-01')
24
+ penguin = Penguin.new(:name => "Mary", :age => 2, :birthday => bday)
23
25
  penguin.save(@conn)
24
26
  penguin.update(:age => 3)
25
27
  penguin.name.should == "Mary"
26
28
  penguin.age.should == 3
29
+ penguin.birthday.should == bday
27
30
  end
28
31
 
29
32
  it "should search upadated attributes" do
30
- penguin = query.where(:name => "Mary").first
31
- penguin.name.should == "Mary"
32
- penguin.age.should == 3
33
+ bday = DateTime.parse('1900-02-02')
34
+ penguin = Penguin.new(:name => "Mary J.", :age => 200, :birthday => bday)
35
+ penguin.save(@conn)
36
+ penguin = query.where(:name => "Mary J.").first
37
+ penguin.name.should == "Mary J."
38
+ penguin.age.should == 200
39
+ penguin.birthday == bday
33
40
  end
34
41
 
35
42
  it "should destroy entity" do
36
- penguin = Penguin.new(:name => "Mary", :age => 2)
43
+ penguin = Penguin.new(:name => "Mary Jo.", :age => 2)
37
44
  penguin.save(@conn)
38
45
  number_of_penguins = Penguin.all.size
39
46
  number_of_penguins.should >= 1
40
47
  penguin.destroy
41
48
  Penguin.all.size.should == (number_of_penguins -1)
42
49
  end
50
+
51
+ it "should find by where query" do
52
+ Penguin.new(name: "Mary Jo.", birthday: DateTime.parse('1900-12-31')).save
53
+ Penguin.new(name: "Mary Jen.", birthday: DateTime.parse('1999-12-31')).save
54
+ Penguin.new(name: "Mary Jr.", birthday: DateTime.parse('2013-01-01')).save
55
+ Penguin.new(name: "Mary Jay.", birthday: DateTime.parse('2011-01-01')).save
56
+ query = Penguin.where(birthday: DateTime.parse('1999-12-31'))
57
+ query.each do |entity|
58
+ entity.birthday.should == DateTime.parse('1999-12-31')
59
+ end
60
+ end
61
+
62
+ it "should find by filter query" do
63
+ Penguin.new(name: "Mary Jo.", birthday: DateTime.parse('1890-12-31'), awesomeness: true).save
64
+ Penguin.new(name: "Mary Jen.", birthday: DateTime.parse('1999-12-31'), awesomeness: true).save
65
+ Penguin.new(name: "Mary Jr.", birthday: DateTime.parse('2013-01-01'), awesomeness: false).save
66
+ Penguin.new(name: "Mary Jay.", birthday: DateTime.parse('1850-02-22'), awesomeness: false).save
67
+ query = Penguin.filter(:<, :birthday, DateTime.parse('1900-01-01'))
68
+ result = query.all
69
+ result.size.should == 2
70
+ result.collect(&:name).should =~ ["Mary Jay.", "Mary Jo."]
71
+
72
+ query = Penguin.where(awesomeness: true).filter(:<, :birthday, DateTime.parse('1900-01-01'))
73
+ result = query.all
74
+ result.size.should == 1
75
+ result.first.name.should == "Mary Jo."
76
+ end
43
77
  end
44
78
 
45
79
  context Choice do
@@ -57,7 +91,7 @@ describe Diametric::Entity, :integration => true, :jruby => true do
57
91
  choice = Choice.new(:item => "Boots", :checked => true)
58
92
  choice.save.should_not be_nil
59
93
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :choice/checked]]", @conn2.db)
60
- choice = Choice.from_dbid_or_entity(result.first.first, @conn2.db)
94
+ choice = Choice.reify(result.first.first, @conn2.db)
61
95
  choice.checked.should be_true
62
96
  end
63
97
  end
@@ -78,7 +112,7 @@ describe Diametric::Entity, :integration => true, :jruby => true do
78
112
  customer = Customer.new(:name => "John Smith", :id => id)
79
113
  customer.save.should_not be_nil
80
114
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :customer/name]]", @conn3.db)
81
- customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
115
+ customer2 = Customer.reify(result.first.first, @conn3.db)
82
116
  customer2.name.should == "John Smith"
83
117
  customer2.id.to_s.should == id.to_s
84
118
  end
@@ -89,7 +123,7 @@ describe Diametric::Entity, :integration => true, :jruby => true do
89
123
  customer = Customer.new(:name => "Wilber Hoe", :id => id)
90
124
  customer.save.should_not be_nil
91
125
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ [?name] :where [?e :customer/name ?name]]", @conn3.db, ["Wilber Hoe"])
92
- customer2 = Customer.from_dbid_or_entity(result.first.first, @conn3.db)
126
+ customer2 = Customer.reify(result.first.first, @conn3.db)
93
127
  customer2.name.should == "Wilber Hoe"
94
128
  customer2.id.to_s.should == id.to_s
95
129
  end
@@ -110,7 +144,7 @@ describe Diametric::Entity, :integration => true, :jruby => true do
110
144
  account = Account.new(:name => "This month's deposits", :deposit => [100.0, 200.0], :amount => 0.0)
111
145
  account.save.should_not be_nil
112
146
  result = Diametric::Persistence::Peer.q("[:find ?e :in $ :where [?e :account/name]]", @conn4.db)
113
- account2 = Customer.from_dbid_or_entity(result.first.first, @conn4.db)
147
+ account2 = Customer.reify(result.first.first, @conn4.db)
114
148
  account2.name.should == account.name
115
149
  account2.amount.should == 0.0
116
150
  account2.deposit.should include(100.0)
@@ -52,6 +52,8 @@ class Penguin
52
52
 
53
53
  attribute :name, String
54
54
  attribute :age, Integer
55
+ attribute :birthday, DateTime
56
+ attribute :awesomeness, Boolean
55
57
  end
56
58
 
57
59
  class Rat
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diametric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clinton N. Dreisbach
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-10 00:00:00.000000000 Z
13
+ date: 2013-11-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: edn
@@ -157,6 +157,7 @@ files:
157
157
  - lib/tasks/diametric_config.rb
158
158
  - lib/value_enums.rb
159
159
  - ext/diametric/DiametricCollection.java
160
+ - ext/diametric/DiametricCommon.java
160
161
  - ext/diametric/DiametricConnection.java
161
162
  - ext/diametric/DiametricDatabase.java
162
163
  - ext/diametric/DiametricEntity.java
@@ -164,6 +165,7 @@ files:
164
165
  - ext/diametric/DiametricObject.java
165
166
  - ext/diametric/DiametricPeer.java
166
167
  - ext/diametric/DiametricService.java
168
+ - ext/diametric/DiametricSet.java
167
169
  - ext/diametric/DiametricUtils.java
168
170
  - ext/diametric/DiametricUUID.java
169
171
  - spec/conf_helper.rb