I want to directly update the concerned lines. How do I do that without having to select the items and updating them one by one in Drift? My current code:
final concernedSongs = await (select(playlistSongs)
..where((tbl) => tbl.order.isBetweenValues(low 1, high)))
.get(); // should just update and decrement the values without reiterating over them
concernedSongs.forEach((song) {
reOrder(song.id, song.order - 1);
});
CodePudding user response:
This is not possible with only dart code at the moment. You should look into using a customStatement. Something like:
await db.customStatement(
"UPDATE 'songs' SET order = order - 1 WHERE order > ? AND order < ?",
[low 1, high],
);
CodePudding user response:
You can use custom queries, Reference To Docs
this query may help you to get some idea,
await db.customStatement("update 'songs'
set order = order-1 where order between ? and ?",
[low 1,high]);