skip to Main Content

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);
      });

2

Answers


  1. 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],
    );
    
    Login or Signup to reply.
  2. 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]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search