@@ -1165,6 +1165,60 @@ describe(`On-Demand Sync Mode`, () => {
11651165 { timeout : 2000 } ,
11661166 )
11671167 } )
1168+
1169+ it ( `should evict rows from collection but preserve them in the SQLite database` , async ( ) => {
1170+ const db = await createDatabase ( )
1171+ await createTestProducts ( db )
1172+
1173+ const collection = createCollection (
1174+ powerSyncCollectionOptions ( {
1175+ database : db ,
1176+ table : APP_SCHEMA . props . products ,
1177+ syncMode : `on-demand` ,
1178+ } ) ,
1179+ )
1180+ onTestFinished ( ( ) => collection . cleanup ( ) )
1181+ await collection . stateWhenReady ( )
1182+
1183+ const electronicsQuery = createLiveQueryCollection ( {
1184+ query : ( q ) =>
1185+ q
1186+ . from ( { product : collection } )
1187+ . where ( ( { product } ) => eq ( product . category , `electronics` ) )
1188+ . select ( ( { product } ) => ( {
1189+ id : product . id ,
1190+ name : product . name ,
1191+ price : product . price ,
1192+ category : product . category ,
1193+ } ) ) ,
1194+ } )
1195+
1196+ await electronicsQuery . preload ( )
1197+
1198+ await vi . waitFor (
1199+ ( ) => {
1200+ expect ( electronicsQuery . size ) . toBe ( 3 )
1201+ } ,
1202+ { timeout : 2000 } ,
1203+ )
1204+
1205+ // Clean up the live query — triggers unload/eviction
1206+ electronicsQuery . cleanup ( )
1207+
1208+ // Wait for eviction to complete
1209+ await vi . waitFor (
1210+ ( ) => {
1211+ expect ( collection . size ) . toBe ( 0 )
1212+ } ,
1213+ { timeout : 2000 } ,
1214+ )
1215+
1216+ // Verify the rows still exist in the underlying SQLite database
1217+ const sqliteRows = await db . getAll (
1218+ `SELECT * FROM products WHERE category = 'electronics'` ,
1219+ )
1220+ expect ( sqliteRows ) . toHaveLength ( 3 )
1221+ } )
11681222 } )
11691223
11701224 describe ( `Edge cases` , ( ) => {
0 commit comments