mosql 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mosql (0.1.0)
4
+ mosql (0.1.1)
5
5
  bson_ext
6
6
  json
7
7
  log4r
@@ -17,7 +17,7 @@ GEM
17
17
  bson (1.8.2)
18
18
  bson_ext (1.8.2)
19
19
  bson (~> 1.8.2)
20
- json (1.7.6)
20
+ json (1.7.7)
21
21
  log4r (1.1.10)
22
22
  metaclass (0.0.1)
23
23
  minitest (3.0.0)
data/lib/mosql/cli.rb CHANGED
@@ -253,11 +253,12 @@ module MoSQL
253
253
  end
254
254
 
255
255
  def sync_object(ns, _id)
256
+ sqlid = @sql.transform_one_ns(ns, { '_id' => _id })['_id']
256
257
  obj = collection_for_ns(ns).find_one({:_id => _id})
257
258
  if obj
258
259
  @sql.upsert_ns(ns, obj)
259
260
  else
260
- @sql.table_for_ns(ns).where(:_id => _id).delete()
261
+ @sql.table_for_ns(ns).where(:_id => sqlid).delete()
261
262
  end
262
263
  end
263
264
 
data/lib/mosql/sql.rb CHANGED
@@ -25,22 +25,24 @@ module MoSQL
25
25
  @db[@schema.table_for_ns(ns).intern]
26
26
  end
27
27
 
28
-
29
- def upsert_ns(ns, obj)
28
+ def transform_one_ns(ns, obj)
30
29
  h = {}
31
30
  cols = @schema.all_columns(@schema.find_ns(ns))
32
31
  row = @schema.transform(ns, obj)
33
32
  cols.zip(row).each { |k,v| h[k] = v }
33
+ h
34
+ end
35
+
36
+ def upsert_ns(ns, obj)
37
+ h = transform_one_ns(ns, obj)
34
38
  upsert(table_for_ns(ns), h)
35
39
  end
36
40
 
37
41
  # obj must contain an _id field. All other fields will be ignored.
38
42
  def delete_ns(ns, obj)
39
- cols = @schema.all_columns(@schema.find_ns(ns))
40
- row = @schema.transform(ns, obj)
41
- sqlid = row[cols.index("_id")]
42
- raise "No _id found in transform of #{obj}" if sqlid.nil?
43
- table_for_ns(ns).where(:_id => sqlid).delete
43
+ h = transform_one_ns(ns, obj)
44
+ raise "No _id found in transform of #{obj.inspect}" if h['_id'].nil?
45
+ table_for_ns(ns).where(:_id => h['_id']).delete
44
46
  end
45
47
 
46
48
  def upsert(table, item)
data/lib/mosql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MoSQL
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -56,4 +56,21 @@ EOF
56
56
  })
57
57
  assert_equal(0, sequel[:sqltable].where(:_id => o['_id'].to_s).count)
58
58
  end
59
+
60
+ it 'handle "u" ops with $set and BSON::ObjectIDs' do
61
+ o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
62
+ @adapter.upsert_ns('mosql_test.collection', o)
63
+
64
+ # $set's are currently a bit of a hack where we read the object
65
+ # from the db, so make sure the new object exists in mongo
66
+ connect_mongo['mosql_test']['collection'].insert(o.merge('var' => 100),
67
+ :w => 1)
68
+
69
+ @cli.handle_op({ 'ns' => 'mosql_test.collection',
70
+ 'op' => 'u',
71
+ 'o2' => { '_id' => o['_id'] },
72
+ 'o' => { '$set' => { 'var' => 100 } },
73
+ })
74
+ assert_equal(100, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var])
75
+ end
59
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel