flutterflutter-moor

flutter moor - update specific column in specific row of table


I need to replace a value in specific column of specific row in moor database, but I don't know it's query. can you bring me an example?


Solution

  • Here is the answer what you wanted to do is:

    Future moveImportantTasksIntoCategory(Category target) {
      // for updates, we use the "companion" version of a generated class. This wraps the
      // fields in a "Value" type which can be set to be absent using "Value.absent()". This
      // allows us to separate between "SET category = NULL" (`category: Value(null)`) and not
      // updating the category at all: `category: Value.absent()`.
      return update(todos)
          ..where((t) => t.title.like('%Important%')))
          ..write(TodosCompanion(category: Value(target.id)));
    }
    

    If you can't understand it. Check my example:

      updateHeaderId(String customerCode, int headerId) {
        update(offlineOrderLines)
          ..where((tbl) => tbl.custCode.equals(customerCode))
          ..write(OfflineOrderLinesCompanion(headerId: Value(headerId)));
      }
    

    In the above example, I want to change headerId of particular customerCode. Do let me know if you have any questions.