slick

How to setup username and password with Slick's source code generator?

别等时光非礼了梦想. 提交于 2019-12-05 03:43:43
Following the directions in this page: http://slick.typesafe.com/doc/2.0.0/code-generation.html we see that something like the following segment of code is required to generate models for mysql tables val url = "jdbc:mysql://127.0.0.1/SOME_DB_SCHEMA?characterEncoding=UTF-8&useUnicode=true" val slickDriver = "scala.slick.driver.MySQLDriver" val jdbcDriver = "com.mysql.jdbc.Driver" val outputFolder = "/some/path" val pkg = "com.pligor.server" scala.slick.model.codegen.SourceCodeGenerator.main( Array(slickDriver, jdbcDriver, url, outputFolder, pkg) ) These parameteres are enough for an H2

Slick - Update full object or more than 22 columns

吃可爱长大的小学妹 提交于 2019-12-05 03:22:33
I've a table user_permissions which has 46 permission columns along with id and created_date . This table has a corresponding UserPermissions class: class UserPermission(val id: Long, val createdDate: Option[Timestamp], val permission1: Boolean, val permission2: Boolean, ... val permission46: Boolean) and slick mapping table class UserPermissions(tag: Tag) extends Table[UserPermission](tag, "users_permissions") { def * = ( id :: createdDate :: permission1 :: permission2 :: ... permission46 :: HNil).shaped <> ( { case x => UserPermission( x(0), x(1), x(2), ... x(47)) }, { UserPermission.unapply

How to count results with a filter using Slick?

♀尐吖头ヾ 提交于 2019-12-05 02:14:52
I face a problem I would like to simplify : (quite sure, I'm doing it wrong in fact). Wanted I would like to count the number of users having an id = 1. In SQL language let's say it is something like this : SELECT COUNT(*) FROM users WHERE id = 1 Code I'm using Slick in it's "lifted" form, so here is my piece of code counting the users : Query(Users.where( _.id === 1).length).first Actually what happens here is that Slick alias ScalaQuery, is actually creating a subquery with the filter cause and then counting the results of the sub-request. SELECT COUNT(*) FROM (SELECT * FROM users WHERE id =

Play framework and Slick automatic database creation

故事扮演 提交于 2019-12-05 01:53:27
问题 I'm using play 2.4 and Slick 3, Is it possible to generate automatically ddl scripts, it is evolutions? In official docs I found some scripts, but where should I place it in play framework? http://slick.typesafe.com/doc/3.1.0/schemas.html Do you know any libs to manage evolutions in code to not write plain SQL? 回答1: I made some workaround with PostgresDriver, I've created module, that prints DDL to file. After every code change I just need to replace 1.sql or later modify next evolution

Scala Slick Lazy Fetch

我的梦境 提交于 2019-12-04 23:34:53
I want to be able to fetch all records from a very big table using Slick. If I try to do this through foreach, for or list fetching; I get an Out Of Memory Exception. Is there any way to use "cursors" with Slick or lazy loading that only fetch the object when needed reducing the amount of memory used? Not sure what do you mean by cursors, but you can fetch partial data using pagination: query.drop(0).take(1000) will take the first 1000 records query.drop(1000).take(1000) will take from 1001 to 2000 lines of the table. But this query efficiency will depend on your database, if it will support

How can I omit case class fields in a slick table mapping?

一曲冷凌霜 提交于 2019-12-04 22:29:34
问题 I'm teaching myself some Scala and am currently getting my feet wet with slick (3.1) + play framework, so maybe the answer is simple here and I'm missing something obvious. I have the following model and Table case class User(id: Long = -1, username: String, passwordHash: String, email: Option[String] = None) class Users(tag: Tag) extends Table[User](tag, "USERS") { def id = column[Long]("ID", O.PrimaryKey, O.AutoInc) def username = column[String]("USERNAME") def email = column[Option[String]

How to define generic type in Scala?

一曲冷凌霜 提交于 2019-12-04 22:16:48
问题 In Slick 2, we can map tables like this: case class Cooler(id: Option[Int], minTemp: Option[Double], maxTemp: Option[Double]) /** * Define table "cooler". */ class Coolers(tag: Tag) extends Table[Cooler](tag, "cooler") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def minTemp = column[Double]("min_temp", O.Nullable) def maxTemp = column[Double]("max_temp", O.Nullable) def * = (id.?, minTemp.?, maxTemp.?) <> (Cooler.tupled, Cooler.unapply _) } object Coolers { val tableQuery =

Slick 3.0: Delete rows from multiple tables in a transaction

て烟熏妆下的殇ゞ 提交于 2019-12-04 21:54:18
I want to delete rows from a few tables. My exact intention is depicted in the pseudo SQL statements below, delete from users where oid={user_oid}; login_infos_oid = select login_infos_oid from users_login_infos where users_oid={user_oid}; delete from users_login_infos where users_oid={user_oid}; delete from password_infos where login_infos_oid={login_infos_oid}; delete from login_infos where oid={login_infos_oid}; users_login_infos table has 2 columns users_oid and login_infos_oid and joins users and login_infos tables . How do I this nicely in Slick 3.x within a transaction? Thanks. I do not

How to call a stored procedure and get return value in Slick (using Scala)

此生再无相见时 提交于 2019-12-04 21:37:43
问题 I'm trying to call a stored procedure from Slick 3.0 (in Play Framework). I've been over and over the documentation, but unfortunately the plain SQL docs at Typesafe never show calling a stored procedure. What seems pretty straightforward is causing a typically obscure Scala error message: val f = Try { val call: DBIO[Int] = sqlu"?=call app_glimpulse_invitation_pkg.n_send_invitation(${i.token}, ${i.recipientAccountId.getOrElse(None)}, ${i.email}, ${i.phoneNumber}, ${requestType})" val result:

Slick 2.1.0 Filter Max Version in a Table

一个人想着一个人 提交于 2019-12-04 21:01:23
I'm trying to get the max version number from a table. My table contents are: id externalId name version 1 10 n1 1 2 65 n2 2 3 10 n3 2 4 77 n4 1 In the table above, we have rows that has the maximum version as 2, so my query has to return this maximum version row for the given externalId that I pass into my query. I'm now stuck up with writing the Slick version of it. Any suggestions, pointers? This is what I have so far: (I pass in the externalId) for { myTable1 <- myTable1Elems if myTable1.version === ( myTable1Elems .filter(_.externalId === s"$externalId") .map(_.version) .max ) } yield