play-slick

Play 2.4 - Slick 3.0.0 - DELETE not working

狂风中的少年 提交于 2019-12-01 15:33:04
问题 I am trying to upgrade to Slick 3.0.0 and Play 2.4 (Scala), but deleting rows is not working. In the code below, everything works: querying all rows, inserting and updating - except delete. package dao import scala.concurrent.Future import models._ import models.Tables._ import play.api.Play import play.api.db.slick.DatabaseConfigProvider import play.api.db.slick.HasDatabaseConfig import play.api.libs.concurrent.Execution.Implicits.defaultContext import slick.driver.JdbcProfile class UserDAO

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 and Async - is it a race condition?

回眸只為那壹抹淺笑 提交于 2019-11-29 07:54:52
Reading Play-Slick DBAction code , I thought that this code might contain a race condition: object DBAction{ // snip def apply(r: (RequestWithDbSession) => Result)(implicit app:Application) = { Action { implicit request => AsyncResult { DB.withSession{ s:scala.slick.session.Session => Future(r( RequestWithDbSession(request,s) ))(executionContext) } } } } The function r runs at a future time, after withSession has returned a Future[Result], and called session.close() . Is there a race condition in this code? I am not sure if that is called a race condition. However to me it seems that you are

Slick: create query conjunctions/disjunctions dynamically

折月煮酒 提交于 2019-11-29 00:08:53
问题 I'm trying to create a typesafe dynamic DSL for a Slick table but not sure how to achieve this. Users can post filters to the server by sending filters in form/json format, and I need to build a Slick query with all that. So basically this means transforming a Scala case class representing my filters to a Slick query. It seems the "predicates" can have 3 different shapes. I've seen the trait CanBeQueryCondition . Can I fold over these different possible shapes? I've seen the extension methods

Returning AutoInc ID after Insert in Slick 2.0

两盒软妹~` 提交于 2019-11-29 00:06:36
问题 I have looked to the ends of the earth for the answer to this question. There is not much info out there on slick 2.0. Below is my code for my Addresses model, how would I have the method create return the id after it made the insert? package models import play.api.Play.current import play.api.db.slick.Config.driver.simple._ import play.api.db.slick.DB object Addresses{ val DB_URL:String = "jdbc:h2:mem:fls-play" val DB_driver:String = "org.h2.Driver" class Addresses(tag: Tag) extends Table[

Slick: query multiple tables/databases with getting column names

雨燕双飞 提交于 2019-11-28 09:31:08
I have methods in my Play app that query database tables with over hundred columns. I can't define case class for each such query, because it would be just ridiculously big and would have to be changed with each alter of the table on the database. I'm using this approach, where result of the query looks like this: Map(columnName1 -> columnVal1, columnName2 -> columnVal2, ...) Example of the code: implicit val getListStringResult = GetResult[List[Any]] ( r => (1 to r.numColumns).map(_ => r.nextObject).toList ) def getSomething(): Map[String, Any] = DB.withSession { val columns = MTable

Play slick and Async - is it a race condition?

China☆狼群 提交于 2019-11-28 01:25:49
问题 Reading Play-Slick DBAction code, I thought that this code might contain a race condition: object DBAction{ // snip def apply(r: (RequestWithDbSession) => Result)(implicit app:Application) = { Action { implicit request => AsyncResult { DB.withSession{ s:scala.slick.session.Session => Future(r( RequestWithDbSession(request,s) ))(executionContext) } } } } The function r runs at a future time, after withSession has returned a Future[Result], and called session.close() . Is there a race condition

Slick: query multiple tables/databases with getting column names

梦想的初衷 提交于 2019-11-27 03:05:42
问题 I have methods in my Play app that query database tables with over hundred columns. I can't define case class for each such query, because it would be just ridiculously big and would have to be changed with each alter of the table on the database. I'm using this approach, where result of the query looks like this: Map(columnName1 -> columnVal1, columnName2 -> columnVal2, ...) Example of the code: implicit val getListStringResult = GetResult[List[Any]] ( r => (1 to r.numColumns).map(_ => r