fluent-kit icon indicating copy to clipboard operation
fluent-kit copied to clipboard

Query metadata

Open 0xTim opened this issue 6 years ago • 8 comments

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.

0xTim avatar May 13 '18 09:05 0xTim

Two-phase commits are a very common and useful pattern in NoSQL too.

vzsg avatar May 13 '18 09:05 vzsg

@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!

tanner0101 avatar May 15 '18 21:05 tanner0101

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.

vzsg avatar May 16 '18 11:05 vzsg

Thanks @vzsg!

tanner0101 avatar May 16 '18 18:05 tanner0101

Hey! Any updates on it? Or at least maybe some workaround for now (for PostgreSQL)?

ypotsiah avatar Jul 18 '23 13:07 ypotsiah

cc @gwynne

0xTim avatar Jul 27 '23 18:07 0xTim

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

ryanmalesic avatar Dec 21 '23 23:12 ryanmalesic

@gwynne I'm pretty sure this came from you originally 😆

0xTim avatar Mar 20 '24 17:03 0xTim