rasti-db 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rasti/db/collection.rb +1 -1
- data/lib/rasti/db/helpers.rb +2 -2
- data/lib/rasti/db/query.rb +1 -1
- data/lib/rasti/db/relations.rb +2 -2
- data/lib/rasti/db/version.rb +1 -1
- data/spec/collection_spec.rb +4 -4
- data/spec/minitest_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e82be256b84a31356c81f62ce16b00a0fa576d23
|
4
|
+
data.tar.gz: e44de553c36041c9f572f3506ff427b68dd77142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 807edc88d2733aa2bc1ba8253596fbc3c6ba8f0e4ae4ac72c156b2f856afbcad5c71035172cc3459176264fb39dcc6447c117afbbe309e260f3c56e7b0b9f6a8
|
7
|
+
data.tar.gz: 8252f75a29543c6e08608753d9ceca667a70ec2c7d05df73a880f1e48922f85b83f25796f37e70f42d95d60f2848b950893491eb0dd0ec938c054ff3b24adc56
|
data/lib/rasti/db/collection.rb
CHANGED
@@ -191,7 +191,7 @@ module Rasti
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def qualified_collection_name
|
194
|
-
schema.nil? ? self.class.collection_name : Sequel
|
194
|
+
schema.nil? ? self.class.collection_name : Sequel[schema][self.class.collection_name]
|
195
195
|
end
|
196
196
|
|
197
197
|
def build_query(filter=nil, &block)
|
data/lib/rasti/db/helpers.rb
CHANGED
@@ -7,8 +7,8 @@ module Rasti
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def with_schema(table, field=nil)
|
10
|
-
qualified_table = schema ? Sequel
|
11
|
-
field ? Sequel
|
10
|
+
qualified_table = schema ? Sequel[schema][table] : table
|
11
|
+
field ? Sequel[qualified_table][field] : qualified_table
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/lib/rasti/db/query.rb
CHANGED
@@ -19,7 +19,7 @@ module Rasti
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def pluck(*attributes)
|
22
|
-
ds = dataset.select(*attributes.map { |attr| Sequel
|
22
|
+
ds = dataset.select(*attributes.map { |attr| Sequel[collection_class.collection_name][attr] })
|
23
23
|
attributes.count == 1 ? ds.map { |r| r[attributes.first] } : ds.map(&:values)
|
24
24
|
end
|
25
25
|
|
data/lib/rasti/db/relations.rb
CHANGED
@@ -125,7 +125,7 @@ module Rasti
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def qualified_relation_collection_name(schema=nil)
|
128
|
-
schema.nil? ? relation_collection_name : Sequel
|
128
|
+
schema.nil? ? relation_collection_name : Sequel[schema][relation_collection_name]
|
129
129
|
end
|
130
130
|
|
131
131
|
def graph_to(rows, db, schema=nil, relations=[])
|
@@ -137,7 +137,7 @@ module Rasti
|
|
137
137
|
|
138
138
|
join_rows = target_collection.dataset
|
139
139
|
.join(relation_name, target_foreign_key => target_collection_class.primary_key)
|
140
|
-
.where(Sequel
|
140
|
+
.where(Sequel[relation_name][source_foreign_key] => pks)
|
141
141
|
.all
|
142
142
|
|
143
143
|
Relations.graph_to join_rows, relations, target_collection_class, db, schema
|
data/lib/rasti/db/version.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -208,16 +208,16 @@ describe 'Collection' do
|
|
208
208
|
db[:users].where(id: 1).count.must_equal 1
|
209
209
|
db[:comments].where(user_id: 1).count.must_equal 3
|
210
210
|
db[:posts].where(user_id: 1).count.must_equal 3
|
211
|
-
db[:comments].join(:posts, id: :post_id).where(Sequel
|
212
|
-
db[:categories_posts].join(:posts, id: :post_id).where(Sequel
|
211
|
+
db[:comments].join(:posts, id: :post_id).where(Sequel[:posts][:user_id] => 1).count.must_equal 3
|
212
|
+
db[:categories_posts].join(:posts, id: :post_id).where(Sequel[:posts][:user_id] => 1).count.must_equal 3
|
213
213
|
|
214
214
|
users.delete_cascade 1
|
215
215
|
|
216
216
|
db[:users].where(id: 1).count.must_equal 0
|
217
217
|
db[:comments].where(user_id: 1).count.must_equal 0
|
218
218
|
db[:posts].where(user_id: 1).count.must_equal 0
|
219
|
-
db[:comments].join(:posts, id: :post_id).where(Sequel
|
220
|
-
db[:categories_posts].join(:posts, id: :post_id).where(Sequel
|
219
|
+
db[:comments].join(:posts, id: :post_id).where(Sequel[:posts][:user_id] => 1).count.must_equal 0
|
220
|
+
db[:categories_posts].join(:posts, id: :post_id).where(Sequel[:posts][:user_id] => 1).count.must_equal 0
|
221
221
|
|
222
222
|
db[:users].count.must_equal 2
|
223
223
|
db[:categories].count.must_equal 3
|
data/spec/minitest_helper.rb
CHANGED
@@ -45,7 +45,7 @@ class Comments < Rasti::DB::Collection
|
|
45
45
|
many_to_one :post
|
46
46
|
|
47
47
|
def posts_commented_by(user_id)
|
48
|
-
dataset.where(Sequel
|
48
|
+
dataset.where(Sequel[:comments][:user_id] => user_id)
|
49
49
|
.join(with_schema(:posts), id: :post_id)
|
50
50
|
.select_all(with_schema(:posts))
|
51
51
|
.map { |row| Post.new row }
|