fluent-kit
fluent-kit copied to clipboard
Query metadata
In many algorithms involving database operations, it is extremely useful to be able to determine how many rows were inserted, updated, or deleted by a given query. In particular this information is critical for enabling efficient "atomic" database operations in concurrent environments. Without knowing the affected model count, it is often necessary to perform additional, relatively expensive DQL queries to determine an appropriate course of action. (This may or may not make much sense for NoSQL databases, I'm not sure.) An example of why this is useful is forthcoming as soon as I think of a good representative use case.
Two-phase commits are a very common and useful pattern in NoSQL too.
@vzsg @0xTim would you guys mind supplying some example code for what this might looks like? Or links to implementations in other frameworks. That would help a ton!
In JDBC, PreparedStatement.executeUpdate
returns an integer – the number of updated rows (explanation here).
In go, sql queries return a Result
that contains a RowAffected field: source.
Thanks @vzsg!
Hey! Any updates on it? Or at least maybe some workaround for now (for PostgreSQL)?
cc @gwynne
Affected rows on update would be a great feature for implementing optimistic locking (i.e. update with filter on etag. If no rows were updated I need to throw a 412 Precondition Failed back to the user)
Tracking from vapor/fluent#537
@gwynne I'm pretty sure this came from you originally 😆