Quill: Update… Returning

25 Mar 2020

Quill: Update... Returning

less than 1 minute read

The first Quill’s release of 2020 is out and besides fixes, it brings some useful features. The first of them is update(...).returning.

As you know, Quill supports insert(...).returning for Postgres (via RETURNING), and more recently, for SQL Server (via OUTPUT) as well.

There’s been an open issue requesting the update ... returning feature quite some time. This feature is now available!

The update returning feature

The new feature works exactly in the same way as insert(...).returning, generating a different SQL according to the database. Given a Product:

case class Product(id: Int, description: String, sku: Long)

And the following quote:

val q = quote {
    .update(lift(Product(16, "Awesome Product", 42L)))
    .returning(p => (p.id, p.description))

When running it using Postgres, the result is:

val updated = pgCtx.run(q)

// UPDATE Product SET id = ?, description = ?, sku = ?
//   RETURNING id, description

And for SQL Server users:

val updated = sqlServerCtx.run(q)

// UPDATE Product SET id = ?, description = ?, sku = ?
//   OUTPUT INSERTED.id, INSERTED.description

Interested in the code changes? Check the pull request out!