slick

Slick 3.0: Delete rows from multiple tables in a transaction

旧街凉风 提交于 2019-12-06 17:09:20
问题 I want to delete rows from a few tables. My exact intention is depicted in the pseudo SQL statements below, delete from users where oid={user_oid}; login_infos_oid = select login_infos_oid from users_login_infos where users_oid={user_oid}; delete from users_login_infos where users_oid={user_oid}; delete from password_infos where login_infos_oid={login_infos_oid}; delete from login_infos where oid={login_infos_oid}; users_login_infos table has 2 columns users_oid and login_infos_oid and joins

How to parametrize Scala Slick queries by WHERE clause conditions?

廉价感情. 提交于 2019-12-06 17:07:37
问题 Assume these two simple queries: def findById(id: Long): Option[Account] = database.withSession { implicit s: Session => val query = for (a <- Accounts if a.id === id) yield a.* query.list.headOption } def findByUID(uid: String): Option[Account] = database.withSession { implicit s: Session => val query = for (a <- Accounts if a.uid === uid) yield a.* query.list.headOption } I would like to rewrite it to remove the boilerplate duplication to something like this: def findBy(criteria: ??? =>

Slick withSession inserts into multiple tables test

百般思念 提交于 2019-12-06 16:50:14
Have two tables say Employees and Department have a test fixture, sessionWrapper , which wraps each test. sessionWrapper is a simple fuunction which creates a new session and rolls back, in a finally block, after test completes running. again tests aren't meant to poluate database and best thing we decied is to rollback data. this is achieved by a simple test fixture, sessionWrapper which wraps each test as shown below. fixture provides session (that it created) to each test. Now I have a test which inserts a Employee record into Employees table. Employees table has FK relatinship with

How to return compound types in Slick's Case-If-Then-Else

时间秒杀一切 提交于 2019-12-06 16:01:00
I just start dipping my toe into Slick. In the coffee-supplier example, I try "Case If Then Else" like this: val q = coffees.withFilter(_.price > 9.0).flatMap({ c => suppliers.withFilter(_.id == c.supID).map({ s => val t = c.name > s.name Case If t Then { (c.name, s.name) } Else { (s.name, c.name) } }) }) The compiler emits an error: could not find implicit value for evidence parameter of type scala.slick.ast.TypedType[(scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])] Case If t Then { (c.name, s.name) } Else { (s.name, c.name) } ^ Much the same error apears for other

Slick logging with slf4j-simple

人走茶凉 提交于 2019-12-06 13:42:50
问题 I am using slf4j-simple in my project. I would like to change logging level for slick to INFO. After reading Logging options for Slick and Class SimpleLogger docsI have tried to add following options to my VM line: -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO -Dlogger.scala.slick=INFO -Dlogger.scala.slick.jdbc.JdbcBackend.statement=INFO -Dorg.slf4j.simpleLogger.log.scala.slick=INFO I see a few INFO level logs comming from jetty, therefore the basic logging seems to be working. I am also able

How to combine multiple columns in one case class field when using lifted embedding?

醉酒当歌 提交于 2019-12-06 09:58:11
问题 We have a MySQL table containing several boolean columns which specify the roles a user may have. Is it possible with slick's lifted embedding to write a type mapper which combines & transforms these multiple columns to one field in the case class User like shown below? case class User(id: Option[Int], nickname: String, role: Seq[Role.Role]) object Users extends Table[(User)]("ask_user") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def nickname = column[String]("nickname") def is

Custom Slick Code Generator 3.0.0

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:49:30
问题 Can slick codegen generate all the mapped case classes outside of the ${container} trait , so that they don't inherit its type? Maybe in another file altogether i.e. Models.scala ? // SuppliersRowsDAA.scala import persistence.Tables object SuppliersRowsDAA { case class Save(sup: Tables.SuppliersRow) } I get this compilation error: [error] /app/src/main/scala/persistence/dal/SuppliersDAA.scala:5: type mismatch; [error] found : persistence.Tables.SuppliersRow [error] required: SuppliersDAA.this

Using DB Function (TRIM(LEADING '0' from column)) in Slick

霸气de小男生 提交于 2019-12-06 09:37:59
I would like to translate an SQL query into a TableQuery : SELECT ..., TRIM(LEADING '0' FROM mycolumn) FROM mytable WHERE TRIM(LEADING '0' FROM mycolumn) = '$key Should become MyTableQuery.filter(<_.mycolumn something something> ) I cannot use an implicit MappedColumnType because I am mapping from String to String and have other String columns in the result. And I have no idea how I would use it in both SELECT and WHERE For the SELECT part, I have created a custom function for mapping the result tuples to my case class, so I only need a solution for the WHERE part. Have read the Coming from

Is there any way to do multiple inserts/updates in Slick?

眉间皱痕 提交于 2019-12-06 08:35:25
问题 In sql we can do something like this: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); Is there any way to do multiple/bulk/batch inserts or updates in Slick? Can we do something similar, at least using SQL plain queries ? 回答1: For inserts, as Andrew answered, you use insertALL. def insertAll(items:Seq[MyCaseClass])(implicit session:Session) = { (items.size) match { case s if s > 0 => try { // basequery is the tablequery object baseQuery.insertAll(tempItems :_*) } catch { case e

Play Slick exception in Specs “Task slick.backend.DatabaseComponent rejected from java.util.concurrent.ThreadPoolExecutor”

£可爱£侵袭症+ 提交于 2019-12-06 06:29:30
I am getting a ThreadPoolException from Slick using Play when running my Spec tests, This is using Play 2.4.x, Slick 3, Specs 2? My test looks like: val jsonHeaders = FakeHeaders(Seq((CONTENT_TYPE, MimeTypes.JSON))) def fakeApp: FakeApplication = FakeApplication(additionalConfiguration = Map( "slick.dbs.default.driver" -> "slick.driver.H2Driver$", "slick.dbs.default.db.driver" -> "org.h2.Driver", "slick.dbs.default.db.url" -> "jdbc:h2:mem:test;MODE=PostgreSQL;DATABASE_TO_UPPER=FALSE" )) "Add new group" in new WithApplication(FakeApp.fakeApp){ val vg = new ViewGroup(0, "Test", "Tests") val add