volt-mongo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/mongo/lib/mongo_adaptor_client.rb +2 -2
- data/app/mongo/lib/mongo_adaptor_server.rb +53 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de39d6ea21dd7173c966c2bd36951928819fd4f
|
4
|
+
data.tar.gz: 9c5b9b5185fa9c3dc6973e23a646f3b3fef9f692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fd5f4f6de16626eb700f0b429a1a8c05ae16196ed0023e134e7671c67386a793b7670cc4df9e7842221a6153a9d5b38ad4e1b2211ebbca5862b4b001602a04e
|
7
|
+
data.tar.gz: f852df5a6fd80cfcfeab530290c4f3e017c8d52ee80728f7429eb96d0ede45109e98776dbaf254799207899e90688176a5a4ca9b63a48b9a86fca550ee754e1d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Volt
|
2
2
|
class DataStore
|
3
3
|
class MongoAdaptorClient < BaseAdaptorClient
|
4
|
-
data_store_methods :find, :where, :skip, :order, :limit
|
4
|
+
data_store_methods :find, :where, :skip, :order, :limit#, :count
|
5
5
|
|
6
6
|
module MongoArrayStore
|
7
7
|
# Find takes a query object
|
@@ -22,7 +22,7 @@ module Volt
|
|
22
22
|
Volt::Persistors::ArrayStore.send(:remove_method, :order)
|
23
23
|
|
24
24
|
# include mongo's methods on ArrayStore
|
25
|
-
Volt::Persistors::ArrayStore.include
|
25
|
+
Volt::Persistors::ArrayStore.send(:include, MongoArrayStore)
|
26
26
|
|
27
27
|
def self.normalize_query(query)
|
28
28
|
query = merge_finds_and_move_to_front(query)
|
@@ -20,6 +20,9 @@ module Volt
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def update(collection, values)
|
23
|
+
values = values.stringify_keys
|
24
|
+
|
25
|
+
to_mongo_id!(values)
|
23
26
|
# TODO: Seems mongo is dumb and doesn't let you upsert with custom id's
|
24
27
|
begin
|
25
28
|
@db[collection].insert(values)
|
@@ -28,8 +31,8 @@ module Volt
|
|
28
31
|
if error.message[/^11000[:]/]
|
29
32
|
# Update because the id already exists
|
30
33
|
update_values = values.dup
|
31
|
-
id = update_values.delete(
|
32
|
-
@db[collection].update({ _id
|
34
|
+
id = update_values.delete('_id')
|
35
|
+
@db[collection].update({ '_id' => id }, update_values)
|
33
36
|
else
|
34
37
|
return { error: error.message }
|
35
38
|
end
|
@@ -39,9 +42,9 @@ module Volt
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def query(collection, query)
|
42
|
-
allowed_methods = %w(find skip limit)
|
45
|
+
allowed_methods = %w(find skip limit count)
|
43
46
|
|
44
|
-
|
47
|
+
result = @db[collection]
|
45
48
|
|
46
49
|
query.each do |query_part|
|
47
50
|
method_name, *args = query_part
|
@@ -50,19 +53,63 @@ module Volt
|
|
50
53
|
fail "`#{method_name}` is not part of a valid query"
|
51
54
|
end
|
52
55
|
|
53
|
-
|
56
|
+
args = args.map do |arg|
|
57
|
+
if arg.is_a?(Hash)
|
58
|
+
arg = arg.stringify_keys
|
59
|
+
end
|
60
|
+
arg
|
61
|
+
end
|
62
|
+
|
63
|
+
if method_name == 'find' && args.size > 0
|
64
|
+
qry = args[0]
|
65
|
+
to_mongo_id!(qry)
|
66
|
+
end
|
67
|
+
|
68
|
+
result = result.send(method_name, *args)
|
54
69
|
end
|
55
70
|
|
56
|
-
|
71
|
+
if result.is_a?(::Mongo::Cursor)
|
72
|
+
result = result.to_a.map do |hash|
|
73
|
+
# Return id instead of _id
|
74
|
+
to_volt_id!(hash)
|
75
|
+
|
76
|
+
# Volt expects symbol keys
|
77
|
+
hash.symbolize_keys
|
78
|
+
end#.tap {|v| puts "QUERY: " + v.inspect }
|
79
|
+
end
|
80
|
+
|
81
|
+
result
|
57
82
|
end
|
58
83
|
|
59
84
|
def delete(collection, query)
|
85
|
+
if query.key?('id')
|
86
|
+
query['_id'] = query.delete('id')
|
87
|
+
end
|
88
|
+
|
60
89
|
@db[collection].remove(query)
|
61
90
|
end
|
62
91
|
|
63
92
|
def drop_database
|
64
93
|
db.connection.drop_database(Volt.config.db_name)
|
65
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
private
|
98
|
+
# Mutate a hash to use id instead of _id
|
99
|
+
def to_volt_id!(hash)
|
100
|
+
if hash.key?('_id')
|
101
|
+
# Run to_s to convert BSON::Id also
|
102
|
+
hash['id'] = hash.delete('_id').to_s
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Mutate a hash to use _id instead of id
|
107
|
+
def to_mongo_id!(hash)
|
108
|
+
if hash.key?('id')
|
109
|
+
hash['_id'] = hash.delete('id')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
66
113
|
end
|
67
114
|
end
|
68
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.4.5
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Mongo database drivers for volt
|