slick-3.0

Mapping Slick query to default projection after modifying column value

二次信任 提交于 2019-12-11 10:48:21
问题 When creating a table query, I would like to modify my select statement by mapping the default table query. However, I cannot find a way to map the value of a column and still map to my case class case class MyRecord(id: Int, name: String, value: Int) class MyTable(tag: Tag) extends Table[MyRecord](tag, "MYTABLE") { def id = column[Int]("id") def name = column[String]("name") def value = column[Int]("value") def * = (id, name, value) <> (MyRecord.tupled, MyRecord.unapply) } lazy val

Need help on comparing DateTime through Slick

亡梦爱人 提交于 2019-12-11 06:49:16
问题 Code: def getDatasetStats(startDate: DateTime, endDate: DateTime) = { val query = for(created <- datasets) yield created.createdOn db.run(query.filter(d => d >= startDate && d <= endDate).size.result) } Table: protected class Datasets(tag: Tag) extends Table[SqlDataset](tag, "datasets") { // format: OFF def id = column[UUID]("id", O.PrimaryKey) def name = column[String]("name") def createdOn = column[DateTime]("created_on") def updatedOn = column[Option[DateTime]]("updated_on") def isPublic =

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

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

How to use StaticQuery in Slick 3.0.0?

丶灬走出姿态 提交于 2019-12-08 16:14:09
问题 In Slick 2.1 I had the code below to execute an sql-query from a file: def fetchResult[T](sql: String)(implicit getResult: GetResult[T]): List[T] = { val query = Q.queryNA[T](sql) try { Database.forDataSource(DB.getDataSource()) .withSession { implicit session => query.list } } catch { case e: Throwable => throw new RunSqlException(s"Query $name execution error", e) } } In Slick 3.0.0 you use dbConfig.db.run method to execute DBIOAction and get a future of the result. But I can't find a way

Slick 3 dynamic groupby - fields from its List[String]

亡梦爱人 提交于 2019-12-08 05:02:34
问题 Lets say i want to execute the query: select columnName1,columnName2,Sum(*) from table group by columnName1,columnName2 where columnName1,columnName2 is supplied from list[string] ("columnName1",columnName2") how can i do it with slick? if the columns are known by compile time, i can easily use the groupBy function: tableQuery.groupBy { r => (r.columnName1,r.columnName2)}.map (case groupName,group) => (groupName._1,groupName._2,group.map(...).avg)} but what about dynamic? 回答1: You can use the

Slick 3 composite list insert in transaction

一曲冷凌霜 提交于 2019-12-08 02:43:43
问题 I need to insert next case classes in transaction with saving ids relation: case class A (id: Long, bList: List[B]) case class B (id: Long, aId: cList: List[C]) case class C (id: Long, bId: Long) I know that its easy to save entity with one list inside: def saveAWithBList(aTableObject: A): Future[Long] = { val saveQuery = (for { savedAId <- (aTable returning table.map(_.id)) += aTableObject savedBRows <- bTable ++= aTableObject.bList.map(_.copy(aId = savedAId)) } yield savedAId)

Slick 3.0 how to update variable column list, which number is know only in Runtime

て烟熏妆下的殇ゞ 提交于 2019-12-07 02:32:14
问题 Is it possible to update variable column list, which number is know only in runtime by slick 3.0? Below is example what I want to do (won't compile) var q: Query[UserTable, UserTable#TableElementType, Seq] = userTable var columns = List[Any]() var values = List[Any]() if (updateCommands.name.isDefined) { columns = q.name :: columns values = updateCommands.name.get :: values } if (updateCommands.surname.isDefined) { columns = q.surname :: columns values = updateCommands.surname.get :: values }

Custom Slick Code Generator 3.0.0

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:49:30
问题 Can slick codegen generate all the mapped case classes outside of the ${container} trait , so that they don't inherit its type? Maybe in another file altogether i.e. Models.scala ? // SuppliersRowsDAA.scala import persistence.Tables object SuppliersRowsDAA { case class Save(sup: Tables.SuppliersRow) } I get this compilation error: [error] /app/src/main/scala/persistence/dal/SuppliersDAA.scala:5: type mismatch; [error] found : persistence.Tables.SuppliersRow [error] required: SuppliersDAA.this

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

霸气de小男生 提交于 2019-12-06 09:37:59
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 result tuples to my case class, so I only need a solution for the WHERE part. Have read the Coming from