slick

How to write database-agnostic Play application and perform first-time database initialization?

拜拜、爱过 提交于 2019-11-29 18:51:30
I'm using Slick with a Play Framework 2.1 and I have some troubles. Given the following entity... package models import scala.slick.driver.PostgresDriver.simple._ case class Account(id: Option[Long], email: String, password: String) object Accounts extends Table[Account]("account") { def id = column[Long]("id", O.PrimaryKey, O.AutoInc) def email = column[String]("email") def password = column[String]("password") def * = id.? ~ email ~ password <> (Account, Account.unapply _) } ...I have to import a package for a specific database driver, but I want to use H2 for testing and PostgreSQL in

How to use Slick's mapped tables with foreign keys?

瘦欲@ 提交于 2019-11-29 18:30:10
问题 I'm struggling with Slick's lifted embedding and mapped tables. The API feels strange to me, maybe just because it is structured in a way that's unfamiliar to me. I want to build a Task/Todo-List. There are two entities: Task: Each task has a an optional reference to the next task. That way a linked list is build. The intention is that the user can order the tasks by his priority. This order is represented by the references from task to task. TaskList: Represents a TaskList with a label and a

Is it possible to use IN clause in plain sql Slick?

孤者浪人 提交于 2019-11-29 16:52:20
问题 For example, I want to create the following query: SELECT c.* FROM Coffees c WHERE c.name IN ('robusta', 'arabica') My attempt failed: val cnames = List("robusta", "arabica") sql""" SELECT c.* FROM Coffees c WHERE c.name IN ${cnames} """ could not find implicit value for parameter pconv: scala.slick.jdbc.SetParameter[List[String]] Is it possible to somehow use in clause in Slick plain sql queries? 回答1: I don't see anything out of the box to handle this. You're best bet is probably something

Scala/Slick plain SQL: retrieve result as a map

 ̄綄美尐妖づ 提交于 2019-11-29 15:34:15
问题 I have a simple method to retrieve a user from a db with Sclick plain SQL method: object Data { implicit val getListStringResult = GetResult[List[String]] ( prs => (1 to prs.numColumns).map(_ => prs.nextString).toList ) def getUser(id: Int): Option[List[String]] = DB.withSession { sql"""SELECT * FROM "user" WHERE "id" = $id""".as[List[String]].firstOption } } The result is List[String] but I would like it to be something like Map[String, String] - column name and value pair map. Is this

Play Slick: How to inject DbConfigProvider in tests

混江龙づ霸主 提交于 2019-11-29 14:26:20
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[JdbcProfile] so I need to pass it the dbConfigProvider thing. For some reason I can't inject the provider

How can I handle a > 22 column table with Slick using nested tuples or HLists?

柔情痞子 提交于 2019-11-29 11:09:49
问题 I'm new to Scala (using 2.10) and Slick (using 2.0-M2). I see that one of the ways to get around the 22 column limit for tables in Slick is to use nested tuples. I can't figure out how to do that, despite finding this partial code on GitHub. Current dev branch Scala (2.11-M5) supports case classes with more than 22 elements, but not tuples with arity > 22. And Slick is not yet distributed for Scala 2.11 pre-releases. How can I define a 33 column table (and have it work with all Slick's

Slick, how to map a query to an inheritance table model?

六月ゝ 毕业季﹏ 提交于 2019-11-29 09:02:11
问题 Slick, how to map a query to an inheritance table model? i.e, I have table A, B, C A is the "parent" table and B & C are "child" tables What I would like to know is how should I model this using slick so A will be abstract and B & C concrete types, and querying for a row in A will result in a B or C object Something like JPA's InheritanceType.TABLE_PER_CLASS . 回答1: We need to do couple of things. First find a way to map the hierarchy to an table. In this case I am using a column that stores

Using Auto Incrementing fields with PostgreSQL and Slick

蹲街弑〆低调 提交于 2019-11-29 06:42:04
问题 How does one insert records into PostgreSQL using AutoInc keys with Slick mapped tables? If I use and Option for the id in my case class and set it to None, then PostgreSQL will complain on insert that the field cannot be null. This works for H2, but not for PostgreSQL: //import scala.slick.driver.H2Driver.simple._ //import scala.slick.driver.BasicProfile.SimpleQL.Table import scala.slick.driver.PostgresDriver.simple._ import Database.threadLocalSession object TestMappedTable extends App{

Slick and filtering by Option columns

ⅰ亾dé卋堺 提交于 2019-11-29 06:23:53
问题 I'm trying to filter against an optional date column with Scala Slick 1.0.1. It may be I just don't see it, but I've got a table that looks something like this: case class UserRole(id:UUID, userID:UUID, role:String) object UserRole extends Table[UserRole]("User_Role") { //(id: Long = 0l, name: String, active: Boolean) extends KeyedEntity[Long] { def id = column[UUID]("ID", O.PrimaryKey) def userID = column[UUID]("user_id") def vendorID = column[UUID]("vendor_id") def role = column[String](

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

纵然是瞬间 提交于 2019-11-29 04:01:17
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! Zip joins are only meaningful when talking about ordered sets. Instead of joining based on the value of a column, you are joining based