Created
November 29, 2019 07:24
-
-
Save softberries/4e255971a995f5695be13463e0c90fda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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