@@ -144,6 +144,7 @@ define_connection!(
144
144
end INTEGER NOT NULL ,
145
145
PRIMARY KEY ( item_id) ,
146
146
FOREIGN KEY ( editor_id, workspace_id) REFERENCES editors( item_id, workspace_id)
147
+ ON DELETE CASCADE
147
148
) STRICT ;
148
149
) ,
149
150
] ;
@@ -211,8 +212,8 @@ impl EditorDb {
211
212
workspace_id: WorkspaceId
212
213
) -> Result <Vec <( usize , usize ) >> {
213
214
SELECT start, end
214
- FROM selections
215
- WHERE item_id = ?1 AND workspace_id = ?2
215
+ FROM editor_selections
216
+ WHERE editor_id = ?1 AND workspace_id = ?2
216
217
}
217
218
}
218
219
@@ -224,7 +225,7 @@ impl EditorDb {
224
225
) -> Result < ( ) > {
225
226
let mut first_selection;
226
227
let mut last_selection = 0_usize ;
227
- for ( count, placeholders) in std:: iter:: once ( "(?, ?, ?, ?)" )
228
+ for ( count, placeholders) in std:: iter:: once ( "(?1 , ?2 , ?, ?)" )
228
229
. cycle ( )
229
230
. take ( selections. len ( ) )
230
231
. chunks ( MAX_QUERY_PLACEHOLDERS / 4 )
@@ -244,16 +245,11 @@ impl EditorDb {
244
245
last_selection = last_selection + count;
245
246
let query = format ! (
246
247
r#"
247
- BEGIN TRANSACTION;
248
-
249
- DELETE FROM editor_selections WHERE item_id = ?1 AND workspace_id = ?2;
250
-
251
- INSERT INTO selections (item_id, workspace_id, start, end)
252
- VALUES ({placeholders});
253
-
254
- COMMIT;
248
+ DELETE FROM editor_selections WHERE editor_id = ?1 AND workspace_id = ?2;
255
249
256
- DELETE FROM editors WHERE workspace_id = ? AND item_id NOT IN ({placeholders})"#
250
+ INSERT INTO editor_selections (editor_id, workspace_id, start, end)
251
+ VALUES {placeholders};
252
+ "#
257
253
) ;
258
254
259
255
let selections = selections[ first_selection..last_selection] . to_vec ( ) ;
@@ -262,8 +258,6 @@ impl EditorDb {
262
258
statement. bind ( & editor_id, 1 ) ?;
263
259
let mut next_index = statement. bind ( & workspace_id, 2 ) ?;
264
260
for ( start, end) in selections {
265
- next_index = statement. bind ( & editor_id, next_index) ?;
266
- next_index = statement. bind ( & workspace_id, next_index) ?;
267
261
next_index = statement. bind ( & start, next_index) ?;
268
262
next_index = statement. bind ( & end, next_index) ?;
269
263
}
0 commit comments