slick-2.0

How to map postgresql custom enum column with Slick2.0.1?

橙三吉。 提交于 2021-02-19 02:57:05
问题 I just can't figure it out. What I am using right now is: abstract class DBEnumString extends Enumeration { implicit val enumMapper = MappedJdbcType.base[Value, String]( _.toString(), s => this.withName(s) ) } And then: object SomeEnum extends DBEnumString { type T = Value val A1 = Value("A1") val A2 = Value("A2") } The problem is, during insert/update JDBC driver for PostgreSQL complains about parameter type being "character varying" when column type is "some_enum", which is reasonable as I

Filtering when using custom column type in Slick

时光怂恿深爱的人放手 提交于 2020-02-20 07:29:44
问题 I'm having some difficulties querying/filtering in Slick 2.1.0 when using a custom column type. A simplified version of my problem: import scala.slick.driver.MySQLDriver.simple._ sealed class Status(val intValue: Int) case object Active extends Status(1) case object Disabled extends Status(2) case object Deleted extends Status(3) case class TableMapping(id: Long, status: Status) class MyTableDefinition(tag: Tag) extends Table[TableMapping](tag, "sometable") { implicit val statusColumnType =

Play slick session connection timeout

試著忘記壹切 提交于 2020-01-05 09:05:40
问题 I'm having a problem with the session and connection handling in play with Slick 2.0.1 and play-slick 0.6.0.1 The error is [SQLException: Timed out waiting for a free available connection.] [...] Caused by: java.sql.SQLException: Timed out waiting for a free available connection. at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:88) ~[bonecp.jar:na] [...] I have a play base controller trait for setting up the explicit session in one place

How to convert query result to case class?

微笑、不失礼 提交于 2020-01-03 17:49:15
问题 I'm using Slick 2.0 and I have the following User case class: case class User(id: Option[Long], email: String, password: String) class Users(tag: Tag) extends Table[User](tag, "user") { def id = column[Long]("id", O.PrimaryKey, O.AutoInc) def email = column[String]("email") def password = column[String]("password") def * = (id.?, email, password) <> ((User.apply _).tupled, User.unapply _) } and I have the following function getting a user via their database id: def findOneById(id: Long) = DB

Slick 2.0: Delete multiple rows

倾然丶 夕夏残阳落幕 提交于 2020-01-03 04:46:11
问题 What I wanted to do is delete the N oldest ids from my table using this function: def deleteOldRows(size: Int)(implicit s: Session): Int = MyTable.sortBy(_.id.asc).take(size).delete This operation throws a SlickException because A query for a DELETE statement must resolve to a comprehension with a single table -- Unsupported shape: Comprehension(fetch = None, offset = None) As stated also on the documentation: A query for deleting must only select from a single table. Any projection is

Generic CRUD operations using Slick 2.0

岁酱吖の 提交于 2020-01-02 06:28:48
问题 I am trying to write a generic CRUD trait for Slick 2.0. The trait should a) provide generic methods to read/update/delete entities as well as b) abstract from the database. Following this slick example (database abstraction) and this article (CRUD trait) I came up with the following (shortened) code snippet: trait Profile { val profile: JdbcProfile } trait Crud[T <: AbstractTable[A], A] { this: Profile => import profile.simple._ val qry: TableQuery[T] def countAll()(implicit session: Session

Scala Slick 2 join on multiple fields?

為{幸葍}努か 提交于 2020-01-02 03:23:06
问题 how can do joins on multiple fields like in example beneath? val ownerId = 1 val contactType = 1 ... val contact = for { (t, c) <- ContactTypes leftJoin Contacts on (_.id === _.typeId && _.ownerId === ownerId) if t.id === contactType } yield (c.?, t) How can I achieve this with Slick 2.0.1? Idelly I need slick to generate this kind of query SELECT x2."contact_id", x2."type_id", x2."owner_id", x2."value", x2."created_on", x2."updated_on", x3."id", x3."type", x3."model" FROM ( SELECT x4."id" AS

Slick 2.0 - update two or more columns

*爱你&永不变心* 提交于 2019-12-25 04:29:28
问题 I know I can update two columns in Slick 2.0 with: val q = for (user <- Users if user.id === id) yield (user.name, user.city) q.update((newName, newCity)) But I've seen something like this working as well which is IMO much nicer syntax: Users.filter(_.id === id).map(u => u.name ~ u.city).update(newName, newCity) This gives me the following error: value ~ is not a member of shortcut.db.Tables.profile.simple.Column I have imported PostgresDriver.simple._ and I just can't figure out why. I also

In Slick is there a way to declar Tables without using a Specific JDBC Driver

空扰寡人 提交于 2019-12-24 15:53:40
问题 In my persistence code all through out the tables, etc. I have the following import import scala.slick.driver.PostgresDriver.simple._ This is nice because it works, but this is a problem because all my code is bound to Postgres exclusively. If I want my production to do Postgres and my test to be HSQLDB, for example, I can't. I'd like to declare which DataSource/Driver when I'm running my persistence manager (which will do the create) instead of at the table declaration. What am I missing?

Slick: Option column filtering

萝らか妹 提交于 2019-12-24 01:15:05
问题 I want to do something like this (this is a made-up example to simplify my actual problem): def findByGender(isMale: Option[Boolean]) = { People.filter(row => row.name.isNotNull && isMale match { case Some(true) => row.wife.isNotNull // find rows where wife column is not null case Some(false) => row.wife.isNull // find rows where wife column is null case None => true // select everything }) } This does not compile because of the last "true". Any better way to do this? 回答1: You have to make it