slick

Start generating auto increment column value from default in slick

♀尐吖头ヾ 提交于 2019-12-08 09:58:26
问题 I having a table column holds auto increment value. I want to start incrementing from specified vlaue. How can i specify this functionality in slick ddl. Code i am using for column of table creation in slick is : def id = column[Long]("id", O.PrimaryKey, O.AutoInc, O.NotNull) I have come across this article but didn't find exact solution. create table "COCKTAIL" ( "ID" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 100000) NOT NULL PRIMARY KEY, "NAME" VARCHAR NOT NULL) Can someone help me

How to return compound types in Slick's Case-If-Then-Else

半世苍凉 提交于 2019-12-08 08:22:51
问题 I just start dipping my toe into Slick. In the coffee-supplier example, I try "Case If Then Else" like this: val q = coffees.withFilter(_.price > 9.0).flatMap({ c => suppliers.withFilter(_.id == c.supID).map({ s => val t = c.name > s.name Case If t Then { (c.name, s.name) } Else { (s.name, c.name) } }) }) The compiler emits an error: could not find implicit value for evidence parameter of type scala.slick.ast.TypedType[(scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])]

How to model an inverse relationship with Slick?

↘锁芯ラ 提交于 2019-12-08 06:54:52
问题 I am trying to model a relationship many-to-many in Slick 3.1.0-M1 This is the example of the Slick documentation // Definition of the SUPPLIERS table class Suppliers(tag: Tag) extends Table[(Int, String, String, String, String, String)](tag, "SUPPLIERS") { def id = column[Int]("SUP_ID", O.PrimaryKey) // This is the primary key column def name = column[String]("SUP_NAME") def street = column[String]("STREET") def city = column[String]("CITY") def state = column[String]("STATE") def zip =

Slick 3.0.0 Aggregate Queries

对着背影说爱祢 提交于 2019-12-08 06:35:30
问题 I'm trying to do a complex querying on two tables. They look like below: Table1: id: name: table2Id: version: Table2: id: comments: Assuming that I have the appropriate Slick classes that represents these tables, I'm trying to get all the elements from Table1 and Table 2 that satisfies the following condition: Table1.table2Id === Table2.id and max(Table1.version) I tried the following: val groupById = (for { elem1 <- table1Elems elem2 <- table2Elems if elem1.id === elem2.id } yield (elem1,

Calculate table column using over table on server side

一个人想着一个人 提交于 2019-12-08 05:44:22
问题 Suppose, there are two tables in db: Table registries : Column | Type | --------------------+-----------------------------+--------- registry_id | integer | not null name | character varying | not null ... uploaded_at | timestamp without time zone | not null Table rows : Column | Type | Modifiers ---------------+-----------------------------+----------- row_id | character varying | not null registry_id | integer | not null row | character varying | not null In real world registries is just a

Slick: How can I combine a SQL LIKE statement with a SQL IN statement

有些话、适合烂在心里 提交于 2019-12-08 05:09:36
问题 I basically would like to replace the following code with something more "slicky": final case class User(firstName: String, lastName: String) def dbAction(lastNameParts: Seq[String]): SqlStreamingAction[Vector[User], User, Effect] implicit val getUserResult = GetResult((r: PositionedResult) => { val resultSet: ResultSet = r.rs User( resultSet.getString(1), resultSet.getString(2) ) }) val pattern = orgIds.mkString("|") sql"""SELECT u.first_name, u.last_name FROM users u WHERE last_name ~*

Slick 3 dynamic groupby - fields from its List[String]

亡梦爱人 提交于 2019-12-08 05:02:34
问题 Lets say i want to execute the query: select columnName1,columnName2,Sum(*) from table group by columnName1,columnName2 where columnName1,columnName2 is supplied from list[string] ("columnName1",columnName2") how can i do it with slick? if the columns are known by compile time, i can easily use the groupBy function: tableQuery.groupBy { r => (r.columnName1,r.columnName2)}.map (case groupName,group) => (groupName._1,groupName._2,group.map(...).avg)} but what about dynamic? 回答1: You can use the

Slick: How can I combine a SQL LIKE statement with a SQL IN statement

。_饼干妹妹 提交于 2019-12-08 04:19:28
I basically would like to replace the following code with something more "slicky": final case class User(firstName: String, lastName: String) def dbAction(lastNameParts: Seq[String]): SqlStreamingAction[Vector[User], User, Effect] implicit val getUserResult = GetResult((r: PositionedResult) => { val resultSet: ResultSet = r.rs User( resultSet.getString(1), resultSet.getString(2) ) }) val pattern = orgIds.mkString("|") sql"""SELECT u.first_name, u.last_name FROM users u WHERE last_name ~* $pattern""".as[User] So the resulting SQL would be: SELECT u.first_name, u.last_name FROM users u WHERE

Scala Playframework not all DB queries get executed

拈花ヽ惹草 提交于 2019-12-08 02:43:27
问题 I'm sending via HTTP Post Request a Json to my Playframework backend. In my backend I validate the Json to a Model. After that, I want to save the entries in my Model to my DB. def parseJSON: Action[AnyContent] = Action.async { request => Future { request.body.asJson.map(_.validate[MyModel] match { case JsSuccess(items, _) => itemsToDBController.saveItems(items) Ok("Success") case JsError(err) => println(err) BadRequest("Json Parse Error") }).getOrElse(BadRequest("Error")) } } One Item

Encrypted database password in Play + Slick + HikariCP application

自作多情 提交于 2019-12-08 02:43:19
问题 I'm using play-slick_2.11-1.0.1 + HikariCP 2.4.1 to access SqlServer in my Play4-based application. The database connection in application.conf : slick.dbs.myDatabase = { driver="com.typesafe.slick.driver.ms.SQLServerDriver$" db{ url = "jdbc:sqlserver://sqlserverhost" driver = com.microsoft.sqlserver.jdbc.SQLServerDriver user = "admin" password = "ENCRYPTED_PASSWORD" } } The problem is that the database password configured here must be encrypted based on our company policy. How can I inject