slick

how can I remove codes creating session in unit test for Play framework and slick

点点圈 提交于 2019-12-12 15:04:23
问题 I'm using play 2.0 and slick. so I write unit test for models like this. describe("add") { it("questions be save") { Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession { // given Questions.ddl.create Questions.add(questionFixture) // when val q = Questions.findById(1) // then // assert!!! } } } it works well but following snippets is dupulicated every unit test. Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession { Questions.ddl.create // test

Conditonally UPDATE fields with Slick String interpolation

混江龙づ霸主 提交于 2019-12-12 13:16:37
问题 I have two Option s: val name: Option[String] = ... val shared: Option[Boolean] = ... I would like to build an UPDATE query that SET s these fields if the above values are Some , but leaves them unchanged if they are None . I have managed to achieve this like so, but I am not so keen on the check for the comma, which is not going to scale if I need to add extra columns. I'm also not so keen on having to use a var . var query = Q.u + "UPDATE wishlist SET" if(name.isDefined) query = query + "

No implementation for play.api.db.slick.DatabaseConfigProvider was bound

ぃ、小莉子 提交于 2019-12-12 10:48:04
问题 I can't get slick to work with play 2.5.x I get the following runtime error: ProvisionException: Unable to provision, see the following errors: 1) No implementation for play.api.db.slick.DatabaseConfigProvider was bound. while locating play.api.db.slick.DatabaseConfigProvider My DAO looks like: @Singleton class UserDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] { import driver.api._ ... } And I just inject it in my

Slick 3.0.0 database agnostism

丶灬走出姿态 提交于 2019-12-12 08:55:15
问题 I started to use Slick 3.0.0 and I like it's succinct syntax. Nevertheless, I wasn't able to find a way to use it in a database agnostic way. In the following example provided in the documentation: http://slick.typesafe.com/doc/3.0.0/gettingstarted.html I'd like to be able to decouple somehow this code of the database used and avoid importing database specific in my code (i.e slick.driver.H2Driver.api._ ). I tried to get rid of it by providing the connection using the cake pattern, but the "

Streaming in slick/scala

拈花ヽ惹草 提交于 2019-12-12 08:41:43
问题 I'm looking at scala/slick streaming, and trying to understand how it works. Here is my test code val bigdata = TableQuery[BigData] val x = db.stream(bigdata.result.transactionally.withStatementParameters(fetchSize = 100)).foreach { (tuple: (Int, UUID)) => println(tuple._1 + " " + tuple._2) Thread.sleep(50)//emulating slow consumer. } Await.result(x, 100000 seconds) While the code is running I enabled postgresql query log to understand whats going under the hood. I see a re-query happening

How to use SQL “LIKE” operator in SLICK

吃可爱长大的小学妹 提交于 2019-12-12 08:17:34
问题 Maybe a silly question. But I have not found an answer so far. So how do you represent the SQL's "LIKE" operator in SLICK ? 回答1: Exactly as you normally would! val query = for { coffee <- Coffees if coffee.name like "%expresso%" } yield (coffee.name, coffee.price) Will generate SQL like SELECT name, price FROM coffees WHERE NAME like '%expresso%'; 来源: https://stackoverflow.com/questions/14700821/how-to-use-sql-like-operator-in-slick

How to avoid Slick exception “A query for an UPDATE statement must select table columns only”

余生颓废 提交于 2019-12-12 05:54:17
问题 I have the following case class (note the Option in the last field) case class BranchVO(sk: Int, name: String, bankSk: Int, bankName: Option[String]) And the following class to have Slick access the database (Note the None in the * method, as the case class has an additional last field): class BranchDB(tag: Tag) extends Table[BranchVO](tag, "branches") { def sk: Rep[Int] = column[Int]("sk", O.PrimaryKey, O.AutoInc) def name: Rep[String] = column[String]("name") def bankSk: Rep[Int] = column

Scala/Slick: 3 way join is not working

谁说我不能喝 提交于 2019-12-12 05:18:20
问题 I have 2 tables (Names and Phones) and another table Groups effectively linking the two (using a foreign key towards Names and Phones). I am trying to query names and phone numbers while some names need not have phone numbers. val q = for { (n, (g, p)) <- names joinLeft groups on (_.id === _.nameId) join phones on (_.phoneId === _.id) // ABOVE LINE DOES NOT COMPILE !!! } yield (n, p) I get "value phoneId is not a member of (Contacts.NameTable, slick.lifted.Rep[Option[Contacts.GroupTable]])"

How to get max(id) of table = Rep[Option[Long]] for subsequent insert, without calling db.run in between

你离开我真会死。 提交于 2019-12-12 04:45:51
问题 I have an insert to a table, that depends on the max id of another table. def add(languageCode: String, typeId: Long, properties: Seq[Property]): Unit = { val dbAction = ( for{ nodeId <- (nodes.all returning nodes.all.map(_.id)) += Node(typeId) language <- (languages.all filter (_.code === languageCode)).result.head _ <- DBIO.seq(properties.map { property => val id = property.id val name = property.key val value = property.value if(id == 0) { val currentPropId: FixedSqlAction[Option[Long],

How to perform leftJoin on tables from different databases(data sources) using Scala Slick?

吃可爱长大的小学妹 提交于 2019-12-12 04:29:11
问题 I have 2 databases (database1 and database2). database1 has table1 with field id database2 has table2 with field id Now how do i perform leftJoin(as shown below) using Slick? SELECT tb1.`id` FROM `database1`.`table1` t1 LEFT JOIN `database1`.`table2` t2 ON t1.`id`=t2.`id` 回答1: I may be wrong here but most existing relational databases don't allow you to span multiple databases within single operation. However, what you showed above is easily achievable by using schema (and I strongly believe