anorm

“In” clause in anorm?

[亡魂溺海] 提交于 2019-12-18 12:54:05
问题 It seems no easy way to use "in" clause in anorm: val ids = List("111", "222", "333") val users = SQL("select * from users where id in ({ids})").on('ids-> ???).as(parser *) How to replace the ??? part? I tried: on('ids -> ids) on('ids -> ids.mkString("'","','","'")) on('ids -> ids.mkString("','") But none works. I see in the discussion the exactly same problem: https://groups.google.com/d/topic/play-framework/qls6dhhdayc/discussion, the author has a complex solution: val params = List(1, 2, 3

Play + Anorm + Postgres - load json value into a case class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 08:55:18
问题 I am using anorm to query and save elements into my postgres database. I have a json column which I want to read as class of my own. So for example if I have the following class case class Table(id: Long, name:String, myJsonColumn:Option[MyClass]) case class MyClass(site: Option[String], user:Option[String]) I am trying to write the following update: DB.withConnection { implicit conn => val updated = SQL( """UPDATE employee |SET name = {name}, my_json_column = {myClass} |WHERE id = {id} """

Scala multiline string placeholder

非 Y 不嫁゛ 提交于 2019-12-14 02:18:54
问题 This question is related to ( Why is there no string interpolation in Scala? ), but deals more specifically with multi-line strings. I've just about bought into Martin's suggestion for simple string placeholder where msg = "Hello {name}!" can be be represented without much difference in Scala today like this: msg = "Hello"+name+"!" However, I don't think that approach holds with multi-line strings. And, in some cases it may be encouraging other poor practices in favor of readability. Note

Flatten a list of Anorm tuples

血红的双手。 提交于 2019-12-13 19:28:07
问题 Given a scala list such as: List( ~(OuterObj,InnerObj1), ~(OuterObj, InnerObj2), ...) Where all the OuterObj's are the same and the InnerObj's can be different, I need to "group" this into a single OuterObj object that contains a list of the InnerObj's. In other words, OuterObj has an attribute innerList that is empty, but I need to transform the original list into a single OuterObj such that: OuterObj.innerList = List(InnerObj1, InnerObj2, ....) I tried using .groupBy(_._1) but this didn't

How to return json from Play Scala controller?

做~自己de王妃 提交于 2019-12-13 06:59:43
问题 I would like to know that how can I return json response data from Play(2.2.x) Scala controller class to display on my view page ? I have json objects in Postgresql database(table name: "test" and having: id and name). Please provide me any solutions for it. I have tried the following cases(a and b), but I am not sure why I am not getting the response(like: names) on my controller, so I can show them on my view page ? since I am very new to Play/Scala and Postgresql. case a. If I give like:

How to get 'Char' values from Postgres with Anorm

Deadly 提交于 2019-12-12 18:12:27
问题 I have a postgres table - CREATE TABLE "Contest" ( id serial NOT NULL, name varchar(100) NOT NULL, type char(1) NOT NULL, status char(1) NOT NULL, ... ) I'm trying to get field values type and status back to my Play 2.x (Anorm) application: val parseContest = { get[Pk[Int]]("id") ~ get[String]("name") ~ get[Char]("type") ~ get[Char]("status") map { case id~name~c_type~status => Contest(id, name, c_type, status) } } and get error: could not find implicit value for parameter extractor: anorm

Scala Anorm Postgresql Error When Storing Byte Array

六眼飞鱼酱① 提交于 2019-12-12 16:06:53
问题 I have a database table in Scala Playframework defined as CREATE TABLE account ( id SERIAL, email TEXT NOT NULL, buffer BYTEA NOT NULL, PRIMARY KEY (id) ); I am using a protocol buffer to serialize an object to a byte array with the following code DB.withConnection{ implicit c=> SQL("INSERT INTO device (buffer,secret) VALUES ({secret},{buffer})").on( "secret"->device.getSecret(), "buffer"->device.toByteArray() ).executeInsert() } The type returned by device.toByteArray() is Array[Byte] which

Anorm String Interpolation not replacing variables

北战南征 提交于 2019-12-12 16:03:30
问题 We are using Scala Play, and I am trying to ensure that all SQL queries are using Anorm's String Interpolation. It works with some queries, but many are not actually replacing the variables before the query is executing. import anorm.SQL import anorm.SqlStringInterpolation object SecureFile { val table = "secure_file" val pk = "secure_file_idx" ... // This method works exactly as I would hope def insert(secureFile: SecureFile): Option[Long] = { DBExec { implicit connection => SQL""" INSERT

Support of PostgreSQL specific array_agg function in scala frameworks?

♀尐吖头ヾ 提交于 2019-12-12 15:52:11
问题 Is there some scala relational database framework (anorm, squeryl, etc...) using postgres-like aggregators to produce lists after a group-by, or at least simulating its use? I would expect two levels of implementation: a "standard" one, where at least any SQL grouping with array_agg is translated to a List of the type which is being aggregated, and a "scala ORM powered" one where some type of join is allowed so that if the aggregation is a foreign key to other table, a List of elements of the

ColumnNotFound problem with Magic in play scala

独自空忆成欢 提交于 2019-12-12 10:58:30
问题 I'm getting a "play.exceptions.JavaExecutionException: ColumnNotFound(comments.id)" in a piece of code after trying to migrate to MySql instead of the memorydb. Postgres support by Magic is almost null. The evolution: create table comments ( id bigint(20) NOT NULL AUTO_INCREMENT, source varchar(255) NOT NULL, target varchar(255) NOT NULL, content text NOT NULL, date bigint NOT NULL, PRIMARY KEY (id) ); The model: case class comments(id: Pk[Long], source: String, target: String, content: