This repository was archived by the owner on Dec 22, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -305,7 +305,7 @@ def handle_op(op)
305
305
if options [ :ignore_delete ]
306
306
log . debug ( "Ignoring delete op on #{ ns } as instructed." )
307
307
else
308
- @sql . table_for_ns ( ns ) . where ( :_id => op [ 'o' ] [ '_id' ] ) . delete
308
+ @sql . delete_ns ( ns , op [ 'o' ] )
309
309
end
310
310
else
311
311
log . info ( "Skipping unknown op #{ op . inspect } " )
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ def table_for_ns(ns)
25
25
@db [ @schema . table_for_ns ( ns ) . intern ]
26
26
end
27
27
28
+
28
29
def upsert_ns ( ns , obj )
29
30
h = { }
30
31
cols = @schema . all_columns ( @schema . find_ns ( ns ) )
@@ -33,6 +34,15 @@ def upsert_ns(ns, obj)
33
34
upsert ( table_for_ns ( ns ) , h )
34
35
end
35
36
37
+ # obj must contain an _id field. All other fields will be ignored.
38
+ 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
44
+ end
45
+
36
46
def upsert ( table , item )
37
47
begin
38
48
upsert! ( table , item )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ def fake_cli
20
20
cli . instance_variable_set ( :@mongo , mongo )
21
21
cli . instance_variable_set ( :@schemamap , @map )
22
22
cli . instance_variable_set ( :@sql , @adapter )
23
+ cli . instance_variable_set ( :@options , { } )
23
24
cli
24
25
end
25
26
@@ -44,4 +45,15 @@ def fake_cli
44
45
} )
45
46
assert_equal ( 27 , sequel [ :sqltable ] . where ( :_id => o [ '_id' ] . to_s ) . select . first [ :var ] )
46
47
end
48
+
49
+ it 'handle "d" ops with BSON::ObjectIds' do
50
+ o = { '_id' => BSON ::ObjectId . new , 'var' => 17 }
51
+ @adapter . upsert_ns ( 'mosql_test.collection' , o )
52
+
53
+ @cli . handle_op ( { 'ns' => 'mosql_test.collection' ,
54
+ 'op' => 'd' ,
55
+ 'o' => { '_id' => o [ '_id' ] } ,
56
+ } )
57
+ assert_equal ( 0 , sequel [ :sqltable ] . where ( :_id => o [ '_id' ] . to_s ) . count )
58
+ end
47
59
end
You can’t perform that action at this time.
0 commit comments