@@ -144,6 +144,7 @@ define_connection!(
144144 end INTEGER NOT NULL ,
145145 PRIMARY KEY ( item_id) ,
146146 FOREIGN KEY ( editor_id, workspace_id) REFERENCES editors( item_id, workspace_id)
147+ ON DELETE CASCADE
147148 ) STRICT ;
148149 ) ,
149150 ] ;
@@ -211,8 +212,8 @@ impl EditorDb {
211212 workspace_id: WorkspaceId
212213 ) -> Result <Vec <( usize , usize ) >> {
213214 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
216217 }
217218 }
218219
@@ -224,7 +225,7 @@ impl EditorDb {
224225 ) -> Result < ( ) > {
225226 let mut first_selection;
226227 let mut last_selection = 0_usize ;
227- for ( count, placeholders) in std:: iter:: once ( "(?, ?, ?, ?)" )
228+ for ( count, placeholders) in std:: iter:: once ( "(?1 , ?2 , ?, ?)" )
228229 . cycle ( )
229230 . take ( selections. len ( ) )
230231 . chunks ( MAX_QUERY_PLACEHOLDERS / 4 )
@@ -244,16 +245,11 @@ impl EditorDb {
244245 last_selection = last_selection + count;
245246 let query = format ! (
246247 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;
255249
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+ "#
257253 ) ;
258254
259255 let selections = selections[ first_selection..last_selection] . to_vec ( ) ;
@@ -262,8 +258,6 @@ impl EditorDb {
262258 statement. bind ( & editor_id, 1 ) ?;
263259 let mut next_index = statement. bind ( & workspace_id, 2 ) ?;
264260 for ( start, end) in selections {
265- next_index = statement. bind ( & editor_id, next_index) ?;
266- next_index = statement. bind ( & workspace_id, next_index) ?;
267261 next_index = statement. bind ( & start, next_index) ?;
268262 next_index = statement. bind ( & end, next_index) ?;
269263 }
0 commit comments