slick

Logging options for Slick

孤街醉人 提交于 2019-11-27 23:16:21
问题 I'm createing a Play 2.1 app, in which I have decided to use Slick for database interaction. However I can't find documentation about how to configure/enable logging for Slick. Anyone knows this? 回答1: Slick doesn't do much of any logging above DEBUG level. In application.conf if you add the line: logger.scala.slick=DEBUG you're going to get deluged with information from the query compiler. You're probably just interested in the session information (Connection pool management, query strings,

View SQL query in Slick

痞子三分冷 提交于 2019-11-27 21:01:54
Is there a way to observe an SQL statement that will be generated by Query ? For example, I have this: val q = actions.filter(v => v.actionHash === hash && v.carriedAt > past) Can I view its underlying raw SQL? Ende Neu Slick 2.X: You can print the query statement as shown on the Slick documentation : val invoker = q.invoker val statement = q.selectStatement For other type of statements look at insertStatement , deleteStatement and updateStatement . Slick 3.X: val res = table.filter(_.id === 1L).result res.statements.foreach(println) Docs . For slick 3.0 println(sortedQuery.result.statements

mapped projection with companion object in SLICK

亡梦爱人 提交于 2019-11-27 19:09:22
问题 I have nested classes/objects and want to store (and retrieve) them in a database by using SLICK. I understand that with SLICK mapped projection would be key. Furthermore I use a companion object to map between nested objects and flat structure (to be stored in the DB table). I want to do something like this (simplified example): case class Foo(id: Int, myBar: Bar) case class Bar(myInt: Int, myString: String) object Foo { def apply(id: Int, myInt: Int, myString: String): Foo = Foo(id, Bar

mapped projection with companion object in SLICK

删除回忆录丶 提交于 2019-11-27 18:53:22
I have nested classes/objects and want to store (and retrieve) them in a database by using SLICK. I understand that with SLICK mapped projection would be key. Furthermore I use a companion object to map between nested objects and flat structure (to be stored in the DB table). I want to do something like this (simplified example): case class Foo(id: Int, myBar: Bar) case class Bar(myInt: Int, myString: String) object Foo { def apply(id: Int, myInt: Int, myString: String): Foo = Foo(id, Bar(myInt, myString)) override def unapply(f: Foo) = (f.id, f.myBar.myInt, f.myBar.myString) } object TTable

What's a zip join? Have you ever heard of that, or a pairwise join?

和自甴很熟 提交于 2019-11-27 18:00:44
问题 This section of Slick's documentation page is quite odd. What is this zip join? It says that it means: a pairwise join of two queries but what that means @.@ I don't know I've tried Googling for both "zip join" and "pairwise join"... but no results to do with databases. I do get this from Wikipedia when I search on "pairwise" though... Could somebody give me some examples illustrating the differences between a zip join and a normal outer or inner join? Thanks! 回答1: Zip joins are only

How to execute DDL only when tables don't exist?

匆匆过客 提交于 2019-11-27 17:51:44
问题 I'm using Slick 1.0 with Play Framework 2.1 and MySQL. I'd like to control the ddl table creation so that it only takes place if the tables don't exist. That is to say that the tables should only get created the first time I start play. How to do it in Slick? 回答1: Since I like to control the creation of my tables individually and keep it DRY, I just tend to add a utility method to my apps: def createIfNotExists(tables: TableQuery[_ <: Table[_]]*)(implicit session: Session) { tables foreach

View SQL query in Slick

有些话、适合烂在心里 提交于 2019-11-27 14:20:19
问题 Is there a way to observe an SQL statement that will be generated by Query ? For example, I have this: val q = actions.filter(v => v.actionHash === hash && v.carriedAt > past) Can I view its underlying raw SQL? 回答1: Slick 2.X: You can print the query statement as shown on the Slick documentation: val invoker = q.invoker val statement = q.selectStatement For other type of statements look at insertStatement , deleteStatement and updateStatement . Slick 3.X: val res = table.filter(_.id === 1L)

Slick 3.0 bulk insert or update (upsert)

大城市里の小女人 提交于 2019-11-27 13:48:09
问题 what is the correct way to do a bulk insertOrUpdate in Slick 3.0? I am using MySQL where the appropriate query would be INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b); MySQL bulk INSERT or UPDATE Here is my current code which is very slow :-( // FIXME -- this is slow but will stop repeats, an insertOrUpdate // functions for a list would be much better val rowsInserted = rows.map { row => await(run(TableQuery[FooTable].insertOrUpdate(row))) }.sum

Insert if not exists in Slick 3.0.0

人走茶凉 提交于 2019-11-27 11:49:52
I'm trying to insert if not exists, I found this post for 1.0.1, 2.0. I found snippet using transactionally in the docs of 3.0.0 val a = (for { ns <- coffees.filter(_.name.startsWith("ESPRESSO")).map(_.name).result _ <- DBIO.seq(ns.map(n => coffees.filter(_.name === n).delete): _*) } yield ()).transactionally val f: Future[Unit] = db.run(a) I'm struggling to write the logic from insert if not exists with this structure. I'm new to Slick and have little experience with Scala. This is my attempt to do insert if not exists outside the transaction... val result: Future[Boolean] = db.run(products

SLICK How to define bidirectional one-to-many relationship for use in case class

允我心安 提交于 2019-11-27 10:58:14
问题 I am using SLICK 1.0.0-RC2. I have defined the following two tables Directorate and ServiceArea where Directorate has a one to many relationship with ServiceArea case class Directorate(dirCode: String, name: String) object Directorates extends Table[Directorate]("DIRECTORATES") { def dirCode = column[String]("DIRECTORATE_CODE", O.PrimaryKey) def name = column[String]("NAME") def * = dirCode ~ name <> (Directorate, Directorate.unapply _) } case class ServiceArea(areaCode: String, dirCode: