Insert if not exists in Slick 3.0.0

It is possible to use a single insert … if not exists query. This avoids multiple database round-trips and race conditions (transactions may not be enough depending on isolation level). def insertIfNotExists(name: String) = users.forceInsertQuery { val exists = (for (u <- users if u.name === name.bind) yield u).exists val insert = (name.bind, None) <> … Read more

scala slick method I can not understand so far

[UPDATE] – added (yet another) explanation on for comprehensions The * method: This returns the default projection – which is how you describe: ‘all the columns (or computed values) I am usually interested’ in. Your table could have several fields; you only need a subset for your default projection. The default projection must match the … Read more