Skip to content

How to reference an old value in an update write statement? #3357

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

You must be logged in to vote

The current documentation on the website for this is not great, and I'll improve that. But companions have a .custom static method on them that can be used to build custom SQL expressions into updates. So you could write your update as

  await (db.update(db.homes)..where((tbl) => tbl.sortedIndex.isBiggerThanValue(oldIndex)))
      .write(HomesCompanion.custom(sortedIndex: db.homes.sortedIndex - const Constant(1)));

Replies: 1 comment 1 reply

Comment options

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

Answer selected by TheSHEEEP
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