slick

Slick 2 aggregation - how to get a scalar result?

心已入冬 提交于 2019-12-11 11:19:50
问题 I have a table with an Int column TIME in it: def time = column[Int]("TIME") The table is mapped to a custom type. I want to find a maximum time value, i.e. to perform a simple aggregation. The example in the documentation seems easy enough: val q = coffees.map(_.price) val q1 = q.min val q2 = q.max However, when I do this, the type of q1 and q2 is Column[Option[Int]] . I can perform a get or getOrElse on this to get a result of type Column[Int] (even this seems somewhat surprising to me - is

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

Where to put my database access methods when using a DAO with Slick 2.0?

拟墨画扇 提交于 2019-12-11 10:24:48
问题 (This question is based on a very similar previous request for help. With the introduction of a DAO and multiple database drivers, the same problem requires a different approach, and I hope warrants a new SO question.) I have a class and Slick Table defined like this: import play.api.db.slick.Profile case class Foo(title: String, description: String, id: Int = 0) trait FooComponent extends Profile { this: Profile => import profile.simple._ class FooTable(tag: Tag) extends Table[Foo](tag, "FOO

How to port Slick 2.1 plain SQL queries to Slick 3.0

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:05:39
问题 The following working code from Slick 2.1 returns a single integer (which in this example, happens to be the result of running a function called "foobar"): def getFoobar(): Int = DB.withSession { val query = Q.queryNA[Int]("select foobar()") query.first } How would one port this to Slick 3.0? According to the Slick 3.0 docs, the query would have to be converted to an DBIOAction. So this is what I've tried: import driver.api._ ... def getFoobar(): Future[Int] = { val query = sql"select foobar(

Slick - optionally including / omitting a large column

六眼飞鱼酱① 提交于 2019-12-11 10:04:13
问题 Suppose I have a table with a number of small columns, and a large (say BLOB) column: case class Thing(id: Int, small1: String, small2: String, small3: String, large: String) class ThingMapping(tag: Tag) extends Table[Thing](tag, "things") { def id = column[Int]("id", O.PrimaryKey, O.NotNull, O.AutoInc) def small1 = column[String]("small1") def small2 = column[String]("small2") def small3 = column[String]("small3") def large = column[String]("large") def * = (id, small1, small2, small3, large

How can I JOIN tables in different databases (on the same server) using Slick?

北慕城南 提交于 2019-12-11 09:58:10
问题 I'd like to do a join on two tables residing in different databases on the same MySQL server, using Slick 2.0. Usually this would just be a matter of referring to the tables via a qualified name, e.g. DB1.TABLE1 . Can someone show me how to do this in Slick? If I don't specify a database in the JDBC connection string, I get an exception. If I do specify one of the databases there, say DB1 , and specify the table name in the Table constructors as DB1.TABLE1 and DB2.TABLE2 , then I get an

Does Scala slick have timeout setting?

久未见 提交于 2019-12-11 09:25:50
问题 I noticed in Play! there are couple of settings I can put in application.conf to specify the connection timeout. Since Play! directly leverages Scala slick, I thought there should be similar settings in Scala slick as well, however I cannot find any reference for it so far. I would be surprised if it is unavailable yet. 回答1: IIRC you configure the connection pool with the Play settings. If you use Slick with a connection pool ( Database.fromDataSource ) you can configure the timeout in the

Slick join with subqueries

只愿长相守 提交于 2019-12-11 08:48:04
问题 I build following SQL Query SELECT v.uuid, d.start_time, d.end_time FROM visits v INNER JOIN visit_dates d ON v.uuid = d.visit_uuid WHERE v.study_environment_site_uuid = (SELECT study_environment_site_uuid FROM visits WHERE uuid = 'e4663612-39f9-4c43-bd86-c4c5a9235b03') AND v.uuid != 'e4663612-39f9-4c43-bd86-c4c5a9235b03' AND d.start_time < (SELECT start_time FROM visit_dates WHERE visit_uuid = 'e4663612-39f9-4c43-bd86-c4c5a9235b03' ORDER BY start_time LIMIT 1) ORDER BY d.start_time; now

Macaddr/Inet type of postgres in slick

匆匆过客 提交于 2019-12-11 08:33:48
问题 My application uses slick (v2.0.0) to manage a postgresql (9.1) database. One of my tables contains network devices and therefore mac- and ip-addresses. I used the postgres types macaddr and inet as they seemed like the perfect tool for the task. Now I want to use slick with lifted emebedding but struggle to define my tables. When I auto generated the code for my tables I noticed that String was used instead of those types but didn't mind. This works fine for reading from the DB but when I

How to select Single column from database using scala Play2.6

半世苍凉 提交于 2019-12-11 07:22:33
问题 I have one table User details Table and it contains below Columns User id,username,Email I want to select email whose user id is 1 and i want the response as in proper JSON Format How to do that In Scala Play 2.6 with Slick Till now I have done this def getPasswqord(username:String):Future[Seq[(String)]]= { val a2 = (sql"""select a.userpassword from user_details_table a where a.Email=$username or a.Mobile_no=$username""".as[(String)]) dbConfig.run(a2) } from this i am getting response in a