fluttersqlitedrift

How do I increment or decrement a column in a update query in Flutter using Drift


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

Solution

  • 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]);