slick

Scala Slick Database Views

筅森魡賤 提交于 2019-12-11 02:53:47
问题 Is there any way to use slick with database views? When I run the standard code generator, nothing about views are listed. I also can't seem to find anything in the documentation mentioning the ability (or lack thereof) to do so. 回答1: Yes it is perfectly possible to use views, but you need to tweak code generation a tiny bit. See here for more specific information: https://github.com/slick/slick/issues/1022 (comment of "mobiworx") 回答2: If you follow the link provided by tfh, the following

Slick 3.0.0 AutoIncrement Composite Key

落爺英雄遲暮 提交于 2019-12-11 02:29:15
问题 I have a table structure as below: Table1: id: Int name: String version: Int The corresponding Slick representation of the table would be: class Table1(tag: Tag) extends Table[(Int, String, Int)](tag, "TABLE1") { def id = column[Int]("ID") def name = column[String]("NAME") def version = column[Int]("VERSION") def pk = primaryKey("pk_a", (id, version)) } How can I make the version to auto increment for that corresponding id? I can have elements like: id name version 1 n1 1 1 n2 2 2 xyz 1 3 bmp

Filtering and mixing monads in Slick for comprehension and Cats

筅森魡賤 提交于 2019-12-11 02:02:05
问题 I have the following objective: Create a monad that adds an user with the following computation flow: Check if an user exists with a specified e-mail, if he doesn't then : Check if the credentials given are ok (password long enough, etc.). If they are ok, then: Save the user to the DB My first "draft" would be something like this: val work: DBIO[UserId] = for { userO <- UserRepository.findByEmail(createdUser.email) //userO is Option[User] //This won't work cause Action.withFilter doesnt exist

How can I split out a Slick interpolated query over multiple lines?

泪湿孤枕 提交于 2019-12-10 23:14:32
问题 Is there any way to split a Slick interpolated query over multiple lines in your code? My queries tend to get rather long. So I look for something like the following: val query = sql"select * from DOCUMENTS " + sql"where language = $lang order by publication_date desc" query.as[ResearchDocument] But this results in type mismatch; found : scala.slick.jdbc.SQLInterpolationResult[String] required: String sql"where language = $lang order by publication_date desc" ^ 回答1: Ok, seems like the Scala

Mapping column types Slick 3.1.1

孤街浪徒 提交于 2019-12-10 23:04:14
问题 I am new to Slick and having a really hard time getting mapping of java.sql.date/time/timestamp mapped into jodatime. trait ColumnTypeMappings { val profile: JdbcProfile import profile.api._ val localTimeFormatter = DateTimeFormat.forPattern("HH:mm:ss") val javaTimeFormatter = new SimpleDateFormat("HH:mm:ss") implicit val myDateColumnType = MappedColumnType.base[LocalDate, Date]( ld => new java.sql.Date(ld.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis), d => new LocalDateTime(d.getTime)

Build error for Scala Slick 2.0.0

喜你入骨 提交于 2019-12-10 21:39:40
问题 I am trying to build scala slick but Getting following errors: adongre@pnq-adongre1:/adongre1/external/scala-slick/slick/project> sbt --version sbt launcher version 0.13.0 adongre@pnq-adongre1:/adongre1/external/scala-slick/slick/project> scala -version Scala code runner version 2.10.3 -- Copyright 2002-2013, LAMP/EPFL adongre@pnq-adongre1:/adongre1/external/scala-slick/slick/project> sbt compile [info] Set current project to project (in build file:/adongre1/external/scala-slick/slick/project

Scala Play Slick RejectedExecutionException on ScalaTest runs

与世无争的帅哥 提交于 2019-12-10 21:10:37
问题 My FlatSpec tests are throwing: java.util.concurrent.RejectedExecutionException: Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@dda460e rejected from java.util.concurrent.ThreadPoolExecutor@4f489ebd[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] But only when I run more than one suite , on the second suite forward; it seems there's something that isn't reset between tests. I'm using OneAppPerSuite to provide the app context. Whenever I use

Scala + Play Framework + Slick - Json as Model Field

一曲冷凌霜 提交于 2019-12-10 20:55:40
问题 I need to save a Json Field as a column of my Play Framework Model. My table parser in DAO is class Table(tag: Tag) extends Table[Model](tag, "tablename") { implicit val configFormat = Json.format[Config] // Fields ... def config = column[Config]("config", O.SqlType("JSON")) // Fields ... } Config is defined as a case class in Model in Play Model folder and has his companion object. Field of this object are Int, Double or String case class Config ( // fields ) object Config { implicit val

How to return a sequence generation for an Id

左心房为你撑大大i 提交于 2019-12-10 19:49:29
问题 In Scala Slick, if you are not using auto-incremented Id, but with sequence generation strategy for the id, how do you return that id? 回答1: Let's say you have the following case class and Slick table: case class User(id: Option[Int], first: String, last: String) object Users extends Table[User]("users") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def first = column[String]("first") def last = column[String]("last") def * = id.? ~ first ~ last <> (User, User.unapply _) } The

Can't access delete method on Slick query

只愿长相守 提交于 2019-12-10 18:15:06
问题 This is very very very frustrating. I have been trying to pick up Slick for a while, and obstacles just keep coming. The concept of Slick is really awesome, but it is very difficult to learn, and unlike Scala, it doesn't have "beginner", "intermediate", and "advanced" style where people in all stages can use it easily. I'm using Play-Slick (Slick 2.0.0) https://github.com/freekh/play-slick, following its Multi-DB cake example: https://github.com/freekh/play-slick/tree/master/samples/play