slick

Slick: Is there a way to create a WHERE clause with a regex?

自闭症网瘾萝莉.ら 提交于 2019-12-10 18:04:20
问题 I look for a slick equivalient to select * from users where last_name ~* '[\w]*son'; So for example when having the following names in the database: first_name | last_name ---------------------- Tore | Isakson John | Smith Solveig | Larsson Marc | Finnigan The result would be first_name | last_name ---------------------- Tore | Isakson Solveig | Larsson My current solution is to interpolate this with an SQLActionBuilder like val pattern = "[\\w]*son" val action = sql""" SELECT * FROM users

Dynamic table name override in Slick table

北城余情 提交于 2019-12-10 16:44:40
问题 I have defined a slick table as below on DB view. Every day we create a dated view matching the same structure with name appended with date as T_SUMMARY_ i.e.T_SUMMARY_20131213. Is there a way in slick where table name can be dynamically overridden to generate required query for a correct dated view. object TSummary extends Table[(String)]("T_SUMMARY") { def id = column[String]("ROWID", O.PrimaryKey) def tNum = column[Int]("T_NUM") def tName = column[Int]("T_NAME") def * = id } 回答1: In Slick

Why are these two Slick queries not equivalent?

本小妞迷上赌 提交于 2019-12-10 14:45:27
问题 As a result of trying to make a Slick query more readable, I have this query constructor, which works val q = Users.filter(_.id === userId) join People on { case (u, p) => u.personId === p.id } joinLeft Addresses on { case ((u, p), a) => p.addressId === a.id } joinLeft Businesses on { case (((u, p), a), b) => p.businessId === b.id } joinLeft Addresses on { case ((((u, p), a), b), ba) => b.flatMap(_.addressId) === ba.id } map { case ((((u, p), a), b), ba) => (p, a, b, ba) } And this one I

Scala/Slick plain SQL: retrieve multiple results into list of maps

守給你的承諾、 提交于 2019-12-10 12:13:20
问题 I have a simple method that retrieves single row from a db table: object Data { implicit val getListStringResult = GetResult[List[Object]] ( r => (1 to r.numColumns).map(_ => r.nextObject).toList ) def getUser(id: Int): Option[Map[String, Object]] = DB.withSession { val columns = MTable.getTables(None, None, None, None).list.filter(_.name.name == "user").head.getColumns.list.map(_.column) sql"""SELECT * FROM "user" WHERE "id" = $id""".as[List[Object]].firstOption.map(columns zip _ toMap) } }

Play-Slick: Is it possible to improve this design (pattern) … and how to call it?

我是研究僧i 提交于 2019-12-10 11:55:27
问题 I'm using Play-Slick versions 2.5.x and 3.1.x respectively. I use Slick's code generator and produce the Slick model from an existing database. Actually I'm shy to admit that I'm DB-design driven and not class-design driven. This is the initial setup: Generated Slick model under generated.Tables._ Generic Slick dao implementation Service layer that builds on top of the Generic Slick dao These are the forces behind the pattern which I temporary called "Pluggable Service" because it allows

How to get around Slick 3.0 schema creation getting errors due to key specs without length

有些话、适合烂在心里 提交于 2019-12-10 11:19:17
问题 If you take the hello-slick-3.0 typesafe activator template and try to use it with MySQL rather than H2, creating the COFFEES table results in the following MySQL JDCB driver exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: BLOB/TEXT column 'COF_NAME' used in key specification without a key length This apparently is due to COF_NAME primary key field's using a SQL TEXT column, instead of say, a VARCHAR column, and consequently running into INNODB's limit of 768 bytes for

Using DB Function (TRIM(LEADING '0' from column)) in Slick

。_饼干妹妹 提交于 2019-12-10 10:31:58
问题 I would like to translate an SQL query into a TableQuery : SELECT ..., TRIM(LEADING '0' FROM mycolumn) FROM mytable WHERE TRIM(LEADING '0' FROM mycolumn) = '$key Should become MyTableQuery.filter(<_.mycolumn something something> ) I cannot use an implicit MappedColumnType because I am mapping from String to String and have other String columns in the result. And I have no idea how I would use it in both SELECT and WHERE For the SELECT part, I have created a custom function for mapping the

Comparing type mapped values in Slick queries

北慕城南 提交于 2019-12-10 09:36:19
问题 Consider the Favorites table object below, we want to write a query to find Favorites by their type (defined below). We have also defined a Typemapper, to map a FavoriteType to a String for the database import scala.slick.driver.PostgresDriver.simple._ //Other imports have been omitted in this question object Favorites extends Table[Favorite]("favorites") { // Convert the favoriteTypes to strings for the database implicit val favoriteMapping: TypeMapper[FavorietType] = MappedTypeMapper.base

Passing Slick 2.0 implicit session in elegant way

会有一股神秘感。 提交于 2019-12-09 23:06:18
问题 I'm new to Slick and Scala. First of take a look at my example table with case class mapping and helper for queries SuitsManager . Now methods of SuitsManager are called by Play! controllers inside DBAction (I'm using play-slick 0.6.0.1). package models import play.api.db.slick._ import play.api.db.slick.Config.driver.simple._ import scala.collection.immutable.HashMap import scala.slick.jdbc.JdbcBackend case class Suit(id:Option[Long], complainant: String, defender: String, litigation: Long,

Slick: combine actions with a Seq of DBIOAction

两盒软妹~` 提交于 2019-12-09 18:24:08
问题 I have the (working) following code: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser) loginInfo <- loginInfoAction _ <- slickUserLoginInfos += DBUserLoginInfo(dbUser.userID, loginInfo.id.get) } yield ()).transactionally with loginInfoAction being a DBIOAction. I would like to change loginInfoActions to a Seq of DBIOAction and for each of them, execute the same DBUserLoginInfo action afterwards. I tried this stupidly: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser)