slick

Dynamically create case class

别等时光非礼了梦想. 提交于 2019-11-27 07:17:42
问题 I am using a csv library that takes a case class and turns it into rows for me to read. The syntax is pretty close to File(path).asCsvReader[caseClass] . Link to library here However the problem is that I want to generate my case class from the tables in my database. I can receive the tables in my database and the types that the columns are (Int, Long, Double, String etc) but I do not know how to dynamically create a case class with that data since I do not know the information at compile

Scala reflection to instantiate scala.slick.lifted.TableQuery

孤街醉人 提交于 2019-11-27 03:28:34
问题 I have this base trait trait MyBase { type M type T <: Table[M] val query: TableQuery[T] } Where TableQuery is scala.slick.lifted.TableQuery My subclasses instantiate TableQuery like so: type M = Account type T = AccountsTable val query = TableQuery[T] I'd like to instantiate the TableQuery in the base trait, possibly by using a lazy val , i.e. lazy val query: TableQuery[T] = { ... } I've been playing around with reflection, but haven't had much luck. 回答1: If I understand correctly, what you

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

Slick codegen & tables with > 22 columns

筅森魡賤 提交于 2019-11-27 02:31:45
问题 I'm new to Slick. I'm creating a test suite for a Java application with Scala, ScalaTest and Slick. I'm using slick to prepare data before the test and to do assertions on the data after the test. The database used has some tables with more than 22 columns. I use slick-codegen to generate my schema code. For tables with more than 22 columns, slick-codegen does not generate a case class, but a HList-based custom type and a companion ‘constructor’ method. As I understand it, this is because the

What does the <> operator do in Slick?

孤人 提交于 2019-11-27 02:08:56
问题 I was walking through the documentation of Slick to setup a quick working prototype. In the Mapped Tables section I see a <> operator in the example mentioned but can't find any documentation for that anywhere. Need help in understanding this. 回答1: The <> operator defines a relation between a Row in the Table and a case class . case class User(id: Option[Int], first: String, last: String) ROW |id | first | last | So the data first is taken out of the Tabels as an n-tuple (left side of <> )

Scala: how to define an abstract copyable superclass for any case class?

主宰稳场 提交于 2019-11-26 23:16:27
问题 Please bear with me, there is some context until the OP makes sense. I'm using Slick 3.1.x and the slick code generator. btw The whole source code can be found in the play-authenticate-usage-scala github project. For this project I'd like to have a slick generic Dao to avoid repeating the same boilerplate code for every model. I have a postgres sql script that creates the database using evolutions here: 1.sql I then invoke a generator that generates the following data model: Tables.scala To

Slick 2.0 Generic CRUD operations

試著忘記壹切 提交于 2019-11-26 20:03:58
问题 I've been looking around on how to implement a generic trait for commons CRUD and other kinds of operations, I looked at this and this and the method specified are working well. What I would like to have is a generic method for insertion, my class looks like this at the moment (non generic implementation): object CampaignModel { val campaigns = TableQuery[Campaign] def insert(campaign: CampaignRow)(implicit s: Session) = { campaigns.insert(campaign) } } What I tried so far, following the

Insert if not exists in Slick 3.0.0

我怕爱的太早我们不能终老 提交于 2019-11-26 15:41:50
问题 I'm trying to insert if not exists, I found this post for 1.0.1, 2.0. I found snippet using transactionally in the docs of 3.0.0 val a = (for { ns <- coffees.filter(_.name.startsWith("ESPRESSO")).map(_.name).result _ <- DBIO.seq(ns.map(n => coffees.filter(_.name === n).delete): _*) } yield ()).transactionally val f: Future[Unit] = db.run(a) I'm struggling to write the logic from insert if not exists with this structure. I'm new to Slick and have little experience with Scala. This is my

scala slick method I can not understand so far

六眼飞鱼酱① 提交于 2019-11-26 06:55:47
问题 I try to understand some Slick works and what it requires. Here it an example: package models case class Bar(id: Option[Int] = None, name: String) object Bars extends Table[Bar](\"bar\") { def id = column[Int](\"id\", O.PrimaryKey, O.AutoInc) // This is the primary key column def name = column[String](\"name\") // Every table needs a * projection with the same type as the table\'s type parameter def * = id.? ~ name <>(Bar, Bar.unapply _) } Could somebody explain me what\'s the purpose of *