slick-2.0

Dynamic query parameters in Slick (sorting)

随声附和 提交于 2019-12-07 13:57:47
问题 I'm trying to convert anorm queries to slick in one of Play 2.3 samples, but I'm not sure how to implement dynamic sorting. This is the original method: def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1, filter: String = "%"): Page[(Computer, Option[Company])] = { val offest = pageSize * page DB.withConnection { implicit connection => val computers = SQL( """ select * from computer left join company on computer.company_id = company.id where computer.name like {filter} order by

Slick - Update full object or more than 22 columns

寵の児 提交于 2019-12-06 23:45:37
问题 I've a table user_permissions which has 46 permission columns along with id and created_date . This table has a corresponding UserPermissions class: class UserPermission(val id: Long, val createdDate: Option[Timestamp], val permission1: Boolean, val permission2: Boolean, ... val permission46: Boolean) and slick mapping table class UserPermissions(tag: Tag) extends Table[UserPermission](tag, "users_permissions") { def * = ( id :: createdDate :: permission1 :: permission2 :: ... permission46 ::

Slick logging with slf4j-simple

人走茶凉 提交于 2019-12-06 13:42:50
问题 I am using slf4j-simple in my project. I would like to change logging level for slick to INFO. After reading Logging options for Slick and Class SimpleLogger docsI have tried to add following options to my VM line: -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO -Dlogger.scala.slick=INFO -Dlogger.scala.slick.jdbc.JdbcBackend.statement=INFO -Dorg.slf4j.simpleLogger.log.scala.slick=INFO I see a few INFO level logs comming from jetty, therefore the basic logging seems to be working. I am also able

Dynamic query parameters in Slick (sorting)

泄露秘密 提交于 2019-12-05 22:40:22
I'm trying to convert anorm queries to slick in one of Play 2.3 samples , but I'm not sure how to implement dynamic sorting. This is the original method: def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1, filter: String = "%"): Page[(Computer, Option[Company])] = { val offest = pageSize * page DB.withConnection { implicit connection => val computers = SQL( """ select * from computer left join company on computer.company_id = company.id where computer.name like {filter} order by {orderBy} nulls last limit {pageSize} offset {offset} """ ).on( 'pageSize -> pageSize, 'offset -> offest,

Generic CRUD operations using Slick 2.0

落爺英雄遲暮 提交于 2019-12-05 11:50:53
I am trying to write a generic CRUD trait for Slick 2.0. The trait should a) provide generic methods to read/update/delete entities as well as b) abstract from the database. Following this slick example (database abstraction) and this article (CRUD trait) I came up with the following (shortened) code snippet: trait Profile { val profile: JdbcProfile } trait Crud[T <: AbstractTable[A], A] { this: Profile => import profile.simple._ val qry: TableQuery[T] def countAll()(implicit session: Session): Int = { qry.length.run } def getAll()(implicit session: Session): List[A] = { qry.list // <-- type

Slick - Update full object or more than 22 columns

吃可爱长大的小学妹 提交于 2019-12-05 03:22:33
I've a table user_permissions which has 46 permission columns along with id and created_date . This table has a corresponding UserPermissions class: class UserPermission(val id: Long, val createdDate: Option[Timestamp], val permission1: Boolean, val permission2: Boolean, ... val permission46: Boolean) and slick mapping table class UserPermissions(tag: Tag) extends Table[UserPermission](tag, "users_permissions") { def * = ( id :: createdDate :: permission1 :: permission2 :: ... permission46 :: HNil).shaped <> ( { case x => UserPermission( x(0), x(1), x(2), ... x(47)) }, { UserPermission.unapply

Slick logging with slf4j-simple

别等时光非礼了梦想. 提交于 2019-12-04 17:26:13
I am using slf4j-simple in my project. I would like to change logging level for slick to INFO. After reading Logging options for Slick and Class SimpleLogger docs I have tried to add following options to my VM line: -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO -Dlogger.scala.slick=INFO -Dlogger.scala.slick.jdbc.JdbcBackend.statement=INFO -Dorg.slf4j.simpleLogger.log.scala.slick=INFO I see a few INFO level logs comming from jetty, therefore the basic logging seems to be working. I am also able to change level of logs shown by using -Dorg.slf4j.simpleLogger.defaultLogLevel=TRACE , but even that

Filtering when using custom column type in Slick

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:11:26
I'm having some difficulties querying/filtering in Slick 2.1.0 when using a custom column type. A simplified version of my problem: import scala.slick.driver.MySQLDriver.simple._ sealed class Status(val intValue: Int) case object Active extends Status(1) case object Disabled extends Status(2) case object Deleted extends Status(3) case class TableMapping(id: Long, status: Status) class MyTableDefinition(tag: Tag) extends Table[TableMapping](tag, "sometable") { implicit val statusColumnType = MappedColumnType.base[Status, Int](statusToInt, intToStatus) def id = column[Long]("ID", O.PrimaryKey, O

Scala slick 2.0 updateAll equivalent to insertALL?

ⅰ亾dé卋堺 提交于 2019-12-02 05:24:34
问题 Looking for a way to do a batch update using slick. Is there an equivalent updateAll to insertALL? Goole research has failed me thus far. I have a list of case classes that have varying status. Each one having a different numeric value so I cannot run the typical update query. At the same time, I want to save the multiple update requests as there could be thousands of records I want to update at the same time. 回答1: It's not clear to me what you are trying to achieve, insert and update are two

Scala slick 2.0 updateAll equivalent to insertALL?

纵饮孤独 提交于 2019-12-01 23:34:50
Looking for a way to do a batch update using slick. Is there an equivalent updateAll to insertALL? Goole research has failed me thus far. I have a list of case classes that have varying status. Each one having a different numeric value so I cannot run the typical update query. At the same time, I want to save the multiple update requests as there could be thousands of records I want to update at the same time. Ende Neu It's not clear to me what you are trying to achieve, insert and update are two different operation, for insert makes sense to have a bulk function, for update it doesn't in my