slick

Scala projections in Slick for only one column

我是研究僧i 提交于 2019-12-01 15:56:09
I'm following the Slick documentation example for autoincrementing fields and I'm having trouble creating a mapped projection that ... well, only has one column. case class UserRole(id: Option[Int], role: String) object UserRoles extends Table[UserRole]("userRole") { def id = column[Int]("ID", O.PrimaryKey, O.AutoInc) def role = column[String]("ROLE") // ... def * = id.? ~ role <> (UserRole, UserRole.unapply _) // NEXT LINE ERRORS OUT def forInsert = role <> ({t => UserRole(None, t._1)}, {(r: UserRole) => Some((r.role))}) returning id } The error is "value <> is not a member of scala.slick

What is the difference between inSet and inSetBind in Slick

笑着哭i 提交于 2019-12-01 15:46:00
The ScalaDoc of the functions has not been filled out. I know that the methods are used for mimicking SQL's IN keyword (eg, SELECT * FROM table WHERE id IN VALUES(1, 42, 101) could be done with table.filter(_.id inSet Seq(1, 42, 101)) ). I don't know what this "bind" version is or how to choose which I should be using. virtualeyes inSet is an unsafe version of inSetBind which generates a safe/escaped sql value based on passed in input. In your example where the value is manually set, the two types of bind are equally safe. Normally with bound parameters you get a performance boost (via

Scala projections in Slick for only one column

五迷三道 提交于 2019-12-01 15:45:59
问题 I'm following the Slick documentation example for autoincrementing fields and I'm having trouble creating a mapped projection that ... well, only has one column. case class UserRole(id: Option[Int], role: String) object UserRoles extends Table[UserRole]("userRole") { def id = column[Int]("ID", O.PrimaryKey, O.AutoInc) def role = column[String]("ROLE") // ... def * = id.? ~ role <> (UserRole, UserRole.unapply _) // NEXT LINE ERRORS OUT def forInsert = role <> ({t => UserRole(None, t._1)}, {(r:

Play 2.4 - Slick 3.0.0 - DELETE not working

狂风中的少年 提交于 2019-12-01 15:33:04
问题 I am trying to upgrade to Slick 3.0.0 and Play 2.4 (Scala), but deleting rows is not working. In the code below, everything works: querying all rows, inserting and updating - except delete. package dao import scala.concurrent.Future import models._ import models.Tables._ import play.api.Play import play.api.db.slick.DatabaseConfigProvider import play.api.db.slick.HasDatabaseConfig import play.api.libs.concurrent.Execution.Implicits.defaultContext import slick.driver.JdbcProfile class UserDAO

Scalatra / Slick and insert IF NOT EXISTS

非 Y 不嫁゛ 提交于 2019-12-01 15:28:10
问题 I am a newbie so hoping for some patience. :) I am trying to populate two tables if a value does not exist. Basically I have: TABLE b ( id VARCHAR(254) PRIMARY KEY NOT NULL ); TABLE d ( id VARCHAR(254) PRIMARY KEY NOT NULL, relay INT NOT NULL, FOREIGN KEY ( relay ) REFERENCES b ( id ) ); so I am trying to write a function that populates the two tables with a new value, if it doesn't exist, or ignores it otherwise... of course wrapped in a transaction: IF (NOT EXISTS(SELECT * FROM b where id=

How to use DateTime in Slick2.0?

情到浓时终转凉″ 提交于 2019-12-01 15:08:14
问题 I want to use DateTime in Slick 2.0 model. I use jodatime: I added the dependencies in Build.scala : "joda-time" % "joda-time" % "2.3", "org.joda" % "joda-convert" % "1.6" I then do: class Comment(tag:Tag) extends Table[(Long, Int, Int, String, Int, DateTime)](tag,"Comment"){ def id=column[Long]("ID", O.PrimaryKey) def rate=column[Int]("rate") def sub=column[Int]("subject") def content=column[Int]("cotent") def user_ID=column[Int]("user") def time=column[DateTime]("time") //-----------an

What is the difference between inSet and inSetBind in Slick

匆匆过客 提交于 2019-12-01 13:51:13
问题 The ScalaDoc of the functions has not been filled out. I know that the methods are used for mimicking SQL's IN keyword (eg, SELECT * FROM table WHERE id IN VALUES(1, 42, 101) could be done with table.filter(_.id inSet Seq(1, 42, 101)) ). I don't know what this "bind" version is or how to choose which I should be using. 回答1: inSet is an unsafe version of inSetBind which generates a safe/escaped sql value based on passed in input. In your example where the value is manually set, the two types

Scala conversion long to datetime

天涯浪子 提交于 2019-12-01 11:59:14
问题 I am using nscala-time (wrapper for Joda Time) and slick for a project. I'm trying to use this clause to write a line to the database: Article.insert(0,"title1", "hellothere", DateTime.now.getMillis.asInstanceOf[Timestamp]) Apparently Slick does not support "dateTime" type defined in Joda Time, and I have to use java.sql.Timestamp instead. So I decide to do a little conversion inside the insert method, using "asInstanceOf". Unfortunately, Scala quickly tells me that Java.Long cannot be

Dynamic OR filtering - Slick

∥☆過路亽.° 提交于 2019-12-01 11:33:36
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? Something like this should work. I had to use a similiar fragment in my own code and it is also close to what cvogt proposes in above comment (I think). val username = Option("")

Slick: dynamic sortBy in a query with left join

两盒软妹~` 提交于 2019-12-01 10:39:48
This is a problem derived from another question . I need to be able to dynamically pass a column to be sorted on in a Slick query which has a left join. The problem in this particular situation is that left joined table becomes optional and I have no idea how to handle that. If I make table Company not optional I'm getting SlickException: Read NULL value for ResultSet column Path Example: def list(filter: String, orderBy: Int) = { DB.withDynSession { val data = for { (computer, company) <- Computer.where(_.name like filter) leftJoin Company on (_.companyId === _.id) } yield (computer, company.