slick

Slick 3.0.0 - update row with only non-null values

巧了我就是萌 提交于 2019-12-01 09:39:17
问题 Having a table with the columns class Data(tag: Tag) extends Table[DataRow](tag, "data") { def id = column[Int]("id", O.PrimaryKey) def name = column[String]("name") def state = column[State]("state") def price = column[Int]("price") def * = (id.?, name, state, price) <> ((DataRow.apply _).tupled, DataRow.unapply) } I'd like to write a function that would select a single row, and update the columns where the supplied values are not null. def update(id: Int, name: Option[String], state: Option

Slick: dynamic sortBy in a query with left join

这一生的挚爱 提交于 2019-12-01 08:36:46
问题 This is a problem derived from another question. I need to be able to dynamically pass a column to be sorted on in a Slick query which has a left join. The problem in this particular situation is that left joined table becomes optional and I have no idea how to handle that. If I make table Company not optional I'm getting SlickException: Read NULL value for ResultSet column Path Example: def list(filter: String, orderBy: Int) = { DB.withDynSession { val data = for { (computer, company) <-

How to use Enums in Scala Slick?

心不动则不痛 提交于 2019-12-01 03:58:34
Want to map MySQL INT bitmask to Slick. I've found this but have little problem how to use it https://github.com/nafg/slick-additions/blob/master/src/main/scala/scala/slick/additions/Enum.scala Any help how should I define object for i.e. mysql column INT(3) with Enum containing 3 values: lets name them a,b,c here. I solved the problem with Enums in the following way (taking your values for an example): import play.api.db.slick.DB import play.api.db.slick.Config.driver.simple._ sealed trait MyEnum case object MyEnumA extends MyEnum case object MyEnumB extends MyEnum case object MyEnumC extends

Play!: Does Slick's DDL replace Evolutions?

我的未来我决定 提交于 2019-12-01 03:04:09
This may be a dumb question but I'm new to Play! & Slick. While using Slick's table.ddl.create I noticed that it doesn't create an evolution but the application still works. Does this replace evolutions? Can I use it in production? Should I? Thanks in advance. Both Slick and the Slick DDL Plugin can only generate code to create or delete your schema, not to evolve it. So you still need Play evolutions or something similar to modify an existing schema along the way. In the Slick team, we are working towards a migration solution (on a lower priority). Many parts are already there, but haven't

Slick generic AND driver agnostic

回眸只為那壹抹淺笑 提交于 2019-12-01 01:08:15
Basically what I want to achieve is a combination of: Slick 3.0.0 database agnostism and Slick 3 reusable generic repository I tried a lot, actually, but I can't get this to work at all. abstract class BaseModel[T <: slick.lifted.AbstractTable[_]](query: TableQuery[T], val driver: JdbcProfile, val dbTableName: String) { lazy val all: TableQuery[T] = TableQuery[T] import driver.api._ def createTable = all.schema.create def dropTable = all.schema.create abstract class BaseTable[B](val tag: Tag) extends Table[B](tag, dbTableName) { def id = column[Long]("id", O.PrimaryKey, O.AutoInc) } } Now here

Updating db row scala slick

余生长醉 提交于 2019-11-30 23:04:21
问题 I have following code which inserts row into table named luczekInfo and function to get data from database. My question is how to make function to update columns from table luczekInfo, on rows returned by get(id) function. What is the best way to update columns values in Slick? def create(profil: luczekInfo): Either[Failure, luczekInfo] = { try { val id = db.withSession { LuczekInfo returning LuczekInfo.id insert profil } Right(profil.copy(id = Some(id))) } catch { case e: SQLException =>

Dynamic query with optional where clauses using Slick 3

强颜欢笑 提交于 2019-11-30 21:03:06
I'm trying to implement a method to return filtered results, based on a set of parameters which may or may not be set. It doesn't seem like chaining multiple filters is possible conditionally, i.e. starting off with one filter... val slickFlights = TableQuery[Flights] val query = slickFlights.filter(_.departureLocation === params("departureLocation").toString) Conditionally adding another filter to the query (if it exists in the Map of params) doesn't seem to work... if (params.contains("arrivalLocation")) { query.filter(_.arrivalLocation === params("arrivalLocation").toString) } Can this sort

Type Projection of Foreign Keys in Scala-Slick

假装没事ソ 提交于 2019-11-30 20:13:45
I'm using Scala, and new to Play and Slick. I'm starting to block out a simple database structure and I'm not sure about the correct way to handle foreign keys and projections. In the example at page bottom it currently doesn't compile because a ForeignKey cannot be lifted directly, so what's the correct way to have query results lift into my type (which is basically this sans methods and additional constructors): case class UserCompanyPermission(pk: UUID, company: Company, user: User, accessLevel: CompanyPermissionLevel) Either I'd like to have the type projection return a

Is it possible to use IN clause in plain sql Slick for integers?

独自空忆成欢 提交于 2019-11-30 20:12:48
There is a similar question here but it doesn't actually answer the question. Is it possible to use IN clause in plain sql Slick? Note that this is actually part of a larger and more complex query, so I do need to use plain sql instead of slick's lifted embedding. Something like the following will be good: val ids = List(2,4,9) sql"SELECT * FROM coffee WHERE id IN ($ids)" Ben Reich The sql prefix unlocks a StringContext where you can set SQL parameters. There is no SQL parameter for a list, so you can easily end up opening yourself up to SQL injection here if you're not careful. There are some

how to get paginated select on slick + postgresql

我与影子孤独终老i 提交于 2019-11-30 19:32:50
In a postgresql database, with slick 3, what's the best way to have pagination? get all rows and do pagination with scala (seems not very efficient) ? static query with limit and offset? is there any other way? You can use take and drop methods on TableQuery objects. They will be translated to limit and offset in the resulting SQL query: val users: TableQuery[UsersTable] = UsersTable.query val firstPartOfUsers = users.drop(0).take(25).result val secondPartOfUsers = users.drop(25).take(25).result Those two actions will be translated to the following SQL queries: select "name", "email", "id"