scalaquery

How to write nested queries in select clause

痞子三分冷 提交于 2019-11-30 02:39:00
问题 I'm trying to produce this SQL with SLICK 1.0.0: select cat.categoryId, cat.title, ( select count(product.productId) from products product right join products_categories productCategory on productCategory.productId = product.productId right join categories c on c.categoryId = productCategory.categoryId where c.leftValue >= cat.leftValue and c.rightValue <= cat.rightValue ) as productCount from categories cat where cat.parentCategoryId = 2; My most successful attempt is (I dropped the "joins"

Slick, how to map a query to an inheritance table model?

六月ゝ 毕业季﹏ 提交于 2019-11-29 09:02:11
问题 Slick, how to map a query to an inheritance table model? i.e, I have table A, B, C A is the "parent" table and B & C are "child" tables What I would like to know is how should I model this using slick so A will be abstract and B & C concrete types, and querying for a row in A will result in a B or C object Something like JPA's InheritanceType.TABLE_PER_CLASS . 回答1: We need to do couple of things. First find a way to map the hierarchy to an table. In this case I am using a column that stores

Slick and filtering by Option columns

ⅰ亾dé卋堺 提交于 2019-11-29 06:23:53
问题 I'm trying to filter against an optional date column with Scala Slick 1.0.1. It may be I just don't see it, but I've got a table that looks something like this: case class UserRole(id:UUID, userID:UUID, role:String) object UserRole extends Table[UserRole]("User_Role") { //(id: Long = 0l, name: String, active: Boolean) extends KeyedEntity[Long] { def id = column[UUID]("ID", O.PrimaryKey) def userID = column[UUID]("user_id") def vendorID = column[UUID]("vendor_id") def role = column[String](

How to make aggregations with slick

只谈情不闲聊 提交于 2019-11-29 01:46:57
问题 I want to force slick to create queries like select max(price) from coffees where ... But slick's documentation doesn't help val q = Coffees.map(_.price) //this is query Query[Coffees.type, ...] val q1 = q.min // this is Column[Option[Double]] val q2 = q.max val q3 = q.sum val q4 = q.avg Because those q1-q4 aren't queries, I can't get the results but can use them inside other queries. This statement for { coffee <- Coffees } yield coffee.price.max generates right query but is deprecated

Using dynamic Datasource with Tomcat

前提是你 提交于 2019-11-28 04:48:10
问题 I'm creating a series of webservices for my application and i have the need to access a different database based on the serviceCode that is passed as a parameter in the webservice call. I setup a basic resource with tomcat to access a database like this <Resource name="jdbc/db_name" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="user" password="pass" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://server_ip:3306/db_name"/> But in

scala slick method I can not understand so far

六眼飞鱼酱① 提交于 2019-11-26 06:55:47
问题 I try to understand some Slick works and what it requires. Here it an example: package models case class Bar(id: Option[Int] = None, name: String) object Bars extends Table[Bar](\"bar\") { def id = column[Int](\"id\", O.PrimaryKey, O.AutoInc) // This is the primary key column def name = column[String](\"name\") // Every table needs a * projection with the same type as the table\'s type parameter def * = id.? ~ name <>(Bar, Bar.unapply _) } Could somebody explain me what\'s the purpose of *