slick

What's the difference between using DatabaseConfig and Database in Slick?

邮差的信 提交于 2019-12-09 18:05:01
问题 I was reading about DatabaseConfig in slick's documentation: On top of the configuration syntax for Database , there is another layer in the form of DatabaseConfig which allows you to configure a Slick driver plus a matching Database together. This makes it easy to abstract over different kinds of database systems by simply changing a configuration file . I don't get this part, how DatabaseConfig makes the underlying database system more abstract than the Database approach? Suppose, i'm using

Scala Slick table inheritance

為{幸葍}努か 提交于 2019-12-09 13:07:32
问题 I have SQL table inheritance implemented this way: Table Shape: Column | Type ------------+--------- shape_id | integer square | foat name | character varying(64) Table Triangle Column | Type ------------+--------- shape_id | integer a | float b | float c | float Foreign-key constraints: "fkey1" FOREIGN KEY (shape_id) REFERENCES Shape(shape_id) Table Circle Column | Type ------------+--------- shape_id | integer r | float Foreign-key constraints: "fkey2" FOREIGN KEY (shape_id) REFERENCES

Play!: Does Slick's DDL replace Evolutions?

假装没事ソ 提交于 2019-12-09 02:22:13
问题 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. 回答1: 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

Slick generic AND driver agnostic

瘦欲@ 提交于 2019-12-09 02:02:28
问题 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)

Scala Slick. Wrong pagination \\w Postgres

孤街醉人 提交于 2019-12-08 20:48:28
I'm trying to make simple pagination using Slick with Postgres, but it does not work as expected. // Table // "users_pkey" PRIMARY KEY, btree (id) // "users_id_idx" btree (id) val id: Column[Option[Long]] = column("id", O.PrimaryKey, O.AutoInc, O.DBType(BigSerial)) // Pagination queries users.drop(0).take(20).sortBy(_.id.desc).list users.drop(20).take(20).sortBy(_.id.desc).list But results are not ordered as expected. Users ordered by id on inside page, e.g. first page will be like 40, 35, 34 ... 4, 2 and second 39, 38, 36, ... 3, 1 . The issue is that you are sorting after taking your values.

Why cannot use compiled Insert statement in Slick

流过昼夜 提交于 2019-12-08 17:42:21
问题 Slick experts I'm learning and playing with Slick, and I have question: the document says the Compiled Query only works for select, update and delete, http://slick.typesafe.com/doc/2.0.0/queries.html#compiled-queries I'm curious why it does not support insert? Does it mean everytime I have to insert a row in the table, the statement needs to be re-compiled by Slick? Is there any way to compile an insert statement? Thanks! 回答1: The documentation should be clearer here. For inserts you would

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 2.0.0-M3 table definition - clarification on the tag attribute

家住魔仙堡 提交于 2019-12-08 15:55:42
问题 I'm working on migrating to slick 2 but I've come across a class that I can't seem to find anywhere. package learningSlick import scala.slick.driver.MySQLDriver.simple._ case class Supplier( snum: String, sname: String, status: Int, city: String ) class Suppliers(tag: Option[String]) extends Table[Supplier](tag, "suppliers") { def snum = column[String]("snum") def sname = column[String]("sname") def status = column[Int]("status") def city = column[String]("city") def * = snum ~ sname ~ status

Select single row based on Id in Slick

坚强是说给别人听的谎言 提交于 2019-12-08 15:07:32
问题 I want to query a single row from user based on Id. I have following dummy code case class User( id: Option[Int], name: String } object Users extends Table[User]("user") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def name = column[String]("name") def * = id ~ name <>(User, User.unapply _) def findById(userId: Int)(implicit session: Session): Option[User] = { val user = this.map { e => e }.where(u => u.id === userId).take(1) val usrList = user.list if (usrList.isEmpty) None else

How can I map a case class with non-default field types to a table in Slick?

心不动则不痛 提交于 2019-12-08 13:09:47
问题 I can do this mapping a case class to a slick database table:- case class SomeTimeStamp(id: Option[Long], timestamp: java.sql.Timestamp ) class TimeStampTable(tag: Tag) extends Table[SomeTimeStamp](tag, "TSTAMP_TABLE") { def id = column[Long]("ID", O.AutoInc, O.PrimaryKey) def time = column[java.sql.Timestamp]("TIME") def * = (id.?, time) <> (SomeTimeStamp.tupled, SomeTimeStamp.unapply) } The case class has fields that are converted to database types by default by slick, so all is well. But