Skip to content

Question regarding using a custom closure/anonymous function for where #3167

Answered by simolus3
piperun asked this question in Q&A
Discussion options

You must be logged in to vote

The issue being that since I'm taking in a Table, I assume that .where doesn't have enough context to be able to know which table it is

Exactly! where doesn't have that information available statically, which is required for the field to be available. This should work if you make updateBatch generic over the table:

  void updateBatch<T extends Table, D>(TableInfo<T, D> table, List<Insertable<D>> rows,
      Expression<bool> Function(T table) where) async {
    await _db.batch((batch) async {
      for (final row in rows) {
        batch.update(table, row, where: where);
      }
    });
  }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@piperun
Comment options

Answer selected by piperun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants