slick

Play Slick: How to inject DbConfigProvider in tests

拜拜、爱过 提交于 2020-01-20 08:10:27
问题 I am using Play 2.5.10, Play-slick 2.0.2, and my activator-generated project comes with scalatest and code like this: class TestSpec extends PlaySpec with OneAppPerSuite {...} I managed to test routes/Actions; now I would test DAO methods on a lower level. I searched the web and SO for a solution, and could not find any that is still up-to-date. A DAO signature is like this: class TestDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider

Play Slick: How to inject DbConfigProvider in tests

寵の児 提交于 2020-01-20 08:09:08
问题 I am using Play 2.5.10, Play-slick 2.0.2, and my activator-generated project comes with scalatest and code like this: class TestSpec extends PlaySpec with OneAppPerSuite {...} I managed to test routes/Actions; now I would test DAO methods on a lower level. I searched the web and SO for a solution, and could not find any that is still up-to-date. A DAO signature is like this: class TestDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider

Slick getting a subclass from a single table inheritance Table

自古美人都是妖i 提交于 2020-01-16 14:06:22
问题 I have used Single Table Inheritance to map my models using Slick, following the example found in this question. How do you run queries which return a given type? Eg in the example above, def getFisicia2():PessoaFisica2 = db.run {???} 来源: https://stackoverflow.com/questions/58589229/slick-getting-a-subclass-from-a-single-table-inheritance-table

How to write readable nested join queries with Slick 3.0

你说的曾经没有我的故事 提交于 2020-01-14 10:45:27
问题 This code is creating a query for use in retrieving a user's profile on a web back end. It creates a query that assembles the necessary information into a DTO (which is just a case class) that is subsequently sent back as JSON. def getProfile(userId: Long)={ val q = for{ ((((u,p),a),b), ba) <- filterById(userId) join People on (_.personId === _.id) joinLeft Addresses on (_._2.addressId === _.id) joinLeft Businesses on (_._1._2.businessId === _.id) joinLeft Addresses on (_._2.flatMap(_

How to add AND to the join SLICK

穿精又带淫゛_ 提交于 2020-01-14 09:53:07
问题 I have the problem writing query in SLICK Here is my request to MySql database: SELECT * FROM readings AS r JOIN parameters AS p LEFT JOIN sensorvalues AS sv ON sv.parameter_id=p.id AND sv.reading_id=r.id How can I write it using SLICK ? It is really lack of info on joins in docs. UPDATE 1 I tried all the combinations even one like this val q = for{ Join(p,sv) <- Parameters leftJoin SensorValues on (_.id is sv.parameter_id) r <- Readings if sv.reading_id is r.id } yield(r,p,sv) In this case

Scala+Slick 3: Inserting the result of one query into another table

ⅰ亾dé卋堺 提交于 2020-01-14 07:50:11
问题 This question is about slick 3.0 or 3.1 (I am flexible about that) I have an intermediate query which I process with map , for , etc. to obtain the result I want. In the end I have a val foo: DBIOAction[Seq[MySchema.Bar], NoStream, Effect.Read] Now I have a val bar: TableQuery[MySchema.Bar] and I want to insert foo in to it. If foo would be a Seq I could simply do bar ++= foo , but it is not. The only way I found is to materialize the result by awaiting it. Like this val query = (bar ++=

Connecting to Mysql using Slick 3.0 - No username, no password and bogus driver does not equal error

房东的猫 提交于 2020-01-14 03:48:39
问题 I'm writing a veery simple scala script to connect to Mysql using slick 3. My build.sbt looks like this: name := "slick_sandbox" version := "1.0" scalaVersion := "2.11.7" libraryDependencies ++= Seq( "com.typesafe.slick" %% "slick" % "3.0.3", "org.slf4j" % "slf4j-nop" % "1.6.4", "mysql" % "mysql-connector-java" % "5.1.6" ) application.conf : Drivder is an intentional mistake; also, I did not provide a db username or password! mysqldb = { url = "jdbc:mysql://localhost/slickdb" driver = com

What's the point of dependency injection if you still have to pass in an argument?

痞子三分冷 提交于 2020-01-07 06:26:21
问题 I'm having a bit of trouble understanding the basic idea of dependency injection. (I'm using Play 2.5 with the play-slick module) Say I have a class Users that needs a database connection. package models @Singleton class Users @Inject() (dbConfigProvider: DatabaseConfigProvider) { private val db = dbConfigProvider.get[JdbcProfile].db private val users = TableQuery[UserTable] private val setupAction = DBIO.seq(users.schema.create) private val setupFuture: Future[Unit] = db.run(setupAction) def

How to pass an array to a slick SQL plain query?

爷,独闯天下 提交于 2020-01-06 06:09:37
问题 How to pass an array to a slick SQL plain query? I tried as follows but it fails: // "com.typesafe.slick" %% "slick" % "3.3.2", // latest version val ids = Array(1, 2, 3) db.run(sql"""select name from person where id in ($ids)""".as[String]) Error: could not find implicit value for parameter e: slick.jdbc.SetParameter[Array[Int]] However this ticket seems to say that it should work: https://github.com/tminglei/slick-pg/issues/131 Note: I am not interested in the following approach: db.run(sql

H2 in-memory database error “Data conversion error converting” when using UUID as primary key

陌路散爱 提交于 2020-01-06 02:32:28
问题 I got the following error when using UUID as primary key with Slick with H2 in-memory database. I've tried to debug this for days, but no luck: Data conversion error converting "00000000-0000-0000-0000-000000000001" Here's the code that can reproduce this issue: import java.util.UUID import slick.driver.H2Driver.api._ import scala.concurrent.Await import scala.concurrent.duration.Duration object Main { class Tasks(tag: Tag) extends Table[(String, Option[UUID])](tag, "tasks") { def name: Rep