slick

Compose “Insert…Select…Where” query

有些话、适合烂在心里 提交于 2019-12-19 19:46:06
问题 I'm trying to compose a query using Slick 3.0, but can't seem to figure it out. The equivalent SQL is "insert into SavedMail select * from Inbox where Inbox.id = 1" val mailTable = TableQuery[Tables.Inbox] val savedMailTable = TableQuery[Tables.Savedmail] val select = mailTable.filter(_.id === msgId) I'm stuck on how to do the insert now. Help appreciated. 回答1: Here's a solution I've come up with. Perhaps there's a way to not use forceInsertQuery, but hey, this works. val mailTable =

How to retrieve the auto incremented ID using slick / plainSQL?

巧了我就是萌 提交于 2019-12-19 11:45:16
问题 Isn't there a slick/plainSQL native solution to retrieve the auto incremented id of the current INSERT? userId is an auto incremental field in my mySQL table. sql""" INSERT INTO `table`(`email`) OUTPUT INSERTED.userId VALUES ("theEmailAdress@test.de") """.as[Int].firstOption Help would be greatly appreciated. Cheers Oliver 回答1: Depends on the database. For MS SQL it's SCOPE_IDENTITY(), for mySQL it's LAST_INSERT_ID(). Try searching for equivalent for your DB if it's none of the above. Added

How to use Enums in Scala Slick?

故事扮演 提交于 2019-12-19 06:00:39
问题 Want to map MySQL INT bitmask to Slick. I've found this but have little problem how to use it https://github.com/nafg/slick-additions/blob/master/src/main/scala/scala/slick/additions/Enum.scala Any help how should I define object for i.e. mysql column INT(3) with Enum containing 3 values: lets name them a,b,c here. 回答1: I solved the problem with Enums in the following way (taking your values for an example): import play.api.db.slick.DB import play.api.db.slick.Config.driver.simple._ sealed

How to do “OR” filter in slick

老子叫甜甜 提交于 2019-12-18 19:44:40
问题 In slick we can use query.filter( m => (m.state === state1 && m.status === status1) || (m.state === state2 && m.status == status2)) for an "OR" condition in where clause. However my requirement is I have "OR" conditions in a list (passed by user as part of URL). Conditions list includes tuples of state and status like List[(state1, status1),(state2, status2),(state3, status3)] So what I wanted was to either be able to build the || statement inside of filter so that I can use each of the

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 are reactive streams used in Slick for inserting data

前提是你 提交于 2019-12-18 04:10:44
问题 In Slick's documentation examples for using Reactive Streams are presented just for reading data as a means of a DatabasePublisher. But what happens when you want to use your database as a Sink and backpreasure based on your insertion rate? I've looked for equivalent DatabaseSubscriber but it doesn't exist. So the question is, if I have a Source, say: val source = Source(0 to 100) how can I crete a Sink with Slick that writes those values into a table with schema: create table NumberTable

Customer Type Mapper for Slick SQL

半腔热情 提交于 2019-12-18 02:45:48
问题 I've found this example from slick testing: https://github.com/slick/slick/blob/master/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MapperTest.scala sealed trait Bool case object True extends Bool case object False extends Bool implicit val boolTypeMapper = MappedColumnType.base[Bool, String]( { b => assertNotNull(b) if(b == True) "y" else "n" }, { i => assertNotNull(i) if(i == "y") True else False } ) But I'm trying to create a TypeMapper for org.joda.time.DateTime to/from

How do you update multiple columns using Slick Lifted Embedding?

邮差的信 提交于 2019-12-17 21:55:02
问题 How do you update multiple columns using Slick Lifted Embedding ? This document doesn't say much. I expected it to be something like this Query(AbilitiesTable).filter((ab: AbilitiesTable.type) => ab.id === ability_id).map((ab: AbilitiesTable.type) => (ab.verb, ab.subject)).update("edit", "doc") 回答1: I figured it out. It should be like this val map = Query(AbilitiesTable) .filter(_.id === ability_id) .map(ab => ab.verb ~ ab.context) map.update(("", "")) Typesafe, why your documentation is so

Slick: Difficulties working with Column[Int] values

时光怂恿深爱的人放手 提交于 2019-12-13 19:26:23
问题 I have a followup to another Slick question I recently asked (Slick table Query: Trouble with recognizing values) here. Please bear with me!! I'm new to databasing and Slick seems especially poor on documentation. Anyway, I have this table: object Users extends Table[(Int, String)]("Users") { def userId = column[Int]("UserId", O.PrimaryKey, O.AutoInc) def userName = column[String]("UserName") def * = userId ~ userName } Part I I'm attempting to query with this function: def findByQuery(where:

Ineer Join query with where in scala slick

别等时光非礼了梦想. 提交于 2019-12-13 11:27:31
问题 I have two tables address ,UserAddressMapping in Adress table Adrressid ,Address is there and in the third table i mapped this userid and Addresss id In sql Select a.Addressid,a.AddressNmae from address table a inner join UserAdrressmaping b on a.Adessressid=b.Adreesid where userid=1 How to write this thing in Scala slick This is far what i have done def innerJoin1(UserId:Int): Future[Seq[UserRegister]] = { val join=address.join(addressid).on(_.Userid === _.UserId) dbConfig.run(join.result )