'Return ids after upsert Slick
I have a query that upserts the data to the database via Slick. I'd like to return the ids of the entities that were inserted. How can I do this using Slick in Scala. Here's a current query and entity defined:
def upsertEntitiesReturn(models: Seq[Entity]): Future[Unit] =
dbRun((models map (entities returning entities).insertOrUpdate),
Seq("entities"))
val entities = TableQuery[Entities]
class Entities(tag: Tag)
extends Table[Entity](tag, Some("service"), "entities") {
private def id = column[String]("id", O.PrimaryKey)
private def name = column[String]("name")
private def description = column[Option[String]]("description")
def `*`: ProvenShape[Entity] =
(id,
name,
description
) <> (
{case (
id,
name,
description
) => Entity(
id,
name,
description
)
}, (a: Entity) =>
Some((
a.Id,
a.Name,
a.Description
))
)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|