Skip to content

Instantly share code, notes, and snippets.

@softberries
Created November 29, 2019 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softberries/4e255971a995f5695be13463e0c90fda to your computer and use it in GitHub Desktop.
Save softberries/4e255971a995f5695be13463e0c90fda to your computer and use it in GitHub Desktop.
def create(name: String, age: Int): Future[Person] = db.run {
// We create a projection of just the name and age columns, since we're not inserting a value for the id column
(people.map(p => (p.name, p.age))
// Now define it to return the id, because we want to know what id was generated for the person
returning people.map(_.id)
// And we define a transformation for the returned value, which combines our original parameters with the
// returned id
into ((nameAge, id) => Person(id, nameAge._1, nameAge._2))
// And finally, insert the person into the database
) += (name, age)
}
def list(): Future[Seq[Person]] = db.run {
people.result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment