scalaquery

SLICK 3.0 - multiple queries depending on one another - db.run(action)

守給你的承諾、 提交于 2021-02-07 05:29:05
问题 I am new to Slick 3 and so far I have understood that db.run are asynchronous call. the .map or .flatMap is run once the Future is returned. The problem in my code below is that all the sub queries do not work (nested db.run). Conceptually speaking, what am I not getting? Is it valid to do this kind of code as below? basically in the .map of the first query I do some actions depending on the first query. I see everywhere for loops with yield , is it the only way to go? Is the problem in my

How to add AND to the join SLICK

穿精又带淫゛_ 提交于 2020-01-14 09:53:07
问题 I have the problem writing query in SLICK Here is my request to MySql database: SELECT * FROM readings AS r JOIN parameters AS p LEFT JOIN sensorvalues AS sv ON sv.parameter_id=p.id AND sv.reading_id=r.id How can I write it using SLICK ? It is really lack of info on joins in docs. UPDATE 1 I tried all the combinations even one like this val q = for{ Join(p,sv) <- Parameters leftJoin SensorValues on (_.id is sv.parameter_id) r <- Readings if sv.reading_id is r.id } yield(r,p,sv) In this case

Dynamic OR filtering - Slick

假如想象 提交于 2019-12-30 11:07:37
问题 Ok, I've got a method with multiple optional arguments like this def(username: Option[String], petname: Option[String], favouritefood: Option[String]) and i want to write a dynamic query that will be capable of fetching the data of defined arguments in a way of this select * from table where un like username or pn like pn or ff like ff; so depending of which arguments are defined to add them to query with OR operator? 回答1: Something like this should work. I had to use a similiar fragment in

How do I specify a Postgresql schema in ScalaQuery?

ⅰ亾dé卋堺 提交于 2019-12-23 11:15:07
问题 I tried, for instance: object WebCache extends Table[(...)]("myschema.mytable") { ... } But that doesn't work. 回答1: Slick now has this functionality: object WebCache extends Table[(...)](Some("myschema"), "mytable") { ... } Should work. 回答2: Got an answer from the scalaquery mailing list. This is a limitation of ScalaQuery. This is not supported at the moment but it should be very easy to add. I've created https://github.com/szeiger/scala-query/issues/19 for this issue. 来源: https:/

Are there plans to support “type providers” for Scala's SIQ (ScalaIntegratedQuery) like in F#?

99封情书 提交于 2019-12-21 03:52:44
问题 The current state of SIQ was presented by Christopher Vogt at ScalaDays 2011. It was shown how queries would work and look like, but as far as I remember there was no notion about how those types would be represented, e. g. if it is still necessary to write boilerplate code to explain the database structure to Scala. F# 3.0 adds type providers (PDC talk by Don Syme: video; GOTO Copenhagen talk by Tomas Petricek: video, slides, blog post), which make it basically unnecessary to manually write

How can I present a many-to-many relationship using a link table with ScalaQuery or SLICK?

跟風遠走 提交于 2019-12-20 09:18:12
问题 I've asked a similar question recently, and got a great reply on solving a many-to-many relationship problem with Lift Mapper. I looked at the ScalaQuery/SLICK documentation but it does not document an approach to persisting data where link tables are involved. If someone knows how to do many-to-many mapping using SLICK, it would be great if you can share it. 回答1: This test (created by Stefan Zeiger) is new in the SLICK test suite, and answers the question quite nicely: def testManyToMany():

How could I know if a database table is exists in ScalaQuery

こ雲淡風輕ζ 提交于 2019-12-18 11:57:28
问题 I'm trying ScalaQuery, it is really amazing. I could defined the database table using Scala class, and query it easily. But I would like to know, in the following code, how could I check if a table is exists, so I won't call 'Table.ddl.create' twice and get a exception when I run this program twice? object Users extends Table[(Int, String, String)]("Users") { def id = column[Int]("id") def first = column[String]("first") def last = column[String]("last") def * = id ~ first ~ last } object

Slick 3.0 - Update columns in a table and return whole table object?

别等时光非礼了梦想. 提交于 2019-12-18 09:33:57
问题 Here is the implementation for Slick 2. Slick 2 - Update columns in a table and return whole table object Does anyone have ideas about how to implement this in Slick 3? 回答1: I was able to make this work by extending the awesome work by Tim Harper in https://stackoverflow.com/a/28148606/310275 Here's what I've done now: package utils import scala.language.existentials import slick.ast._ import slick.driver.PostgresDriver._ import slick.driver.PostgresDriver.api._ import slick.jdbc.{GetResult,

How to use SQL “LIKE” operator in SLICK

吃可爱长大的小学妹 提交于 2019-12-12 08:17:34
问题 Maybe a silly question. But I have not found an answer so far. So how do you represent the SQL's "LIKE" operator in SLICK ? 回答1: Exactly as you normally would! val query = for { coffee <- Coffees if coffee.name like "%expresso%" } yield (coffee.name, coffee.price) Will generate SQL like SELECT name, price FROM coffees WHERE NAME like '%expresso%'; 来源: https://stackoverflow.com/questions/14700821/how-to-use-sql-like-operator-in-slick

How to reference a column by name in slick plain SQL?

久未见 提交于 2019-12-12 03:49:44
问题 I would like to use named references instead of positional in GetResult, so that instead of this: implicit val getCoffeeResult = GetResult(r => Coffee(r.<<, r.<<, r.<<)) i could write something like this: implicit val getCoffeeResult = GetResult(r => Coffee(r.get("name"), r.get("supID"),r.get("price"))) I can has named result? 回答1: You can get it through the resultset: r.rs.getString("name") 来源: https://stackoverflow.com/questions/15452732/how-to-reference-a-column-by-name-in-slick-plain-sql