anorm

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

不问归期 提交于 2021-02-11 12:35:58
问题 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} """

Anorm Mysql Stored Procedure calling

烈酒焚心 提交于 2020-01-24 13:20:06
问题 This is my simple stored procedure , DELIMITER $$ USE `TestDB`$$ DROP PROCEDURE IF EXISTS `test123`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `test123`(id INT(11) , user_name VARCHAR(15), branch VARCHAR(15)) BEGIN INSERT INTO Testlog(id,user_name,branch) VALUES(id,user_name,branch); END$$ DELIMITER ; i can run above stored procedure with below command in mysql CALL `TestDB`.test123(3,"swap","desc") but using anorm how to do that?? DB.withConnection { implicit c => SQL("EXCE test123 {id},

Anorm Mysql Stored Procedure calling

若如初见. 提交于 2020-01-24 13:20:01
问题 This is my simple stored procedure , DELIMITER $$ USE `TestDB`$$ DROP PROCEDURE IF EXISTS `test123`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `test123`(id INT(11) , user_name VARCHAR(15), branch VARCHAR(15)) BEGIN INSERT INTO Testlog(id,user_name,branch) VALUES(id,user_name,branch); END$$ DELIMITER ; i can run above stored procedure with below command in mysql CALL `TestDB`.test123(3,"swap","desc") but using anorm how to do that?? DB.withConnection { implicit c => SQL("EXCE test123 {id},

Play Anorm insert a scala List into a postgres text array column

蓝咒 提交于 2020-01-04 05:37:13
问题 I'm trying to insert a List[String] into a postgresql column of type text[]. I believe when you attempt to insert any List, Anorm inserts each member of the List in its own column. I'm pretty sure this is the case because I get back the exception: org.postgresql.util.PSQLException: ERROR: INSERT has more expressions than target columns What I want to do is insert the entire List as a text[]. My current code: def insertList(listName: String, subLists: List[String]): Long = { DB.withConnection

Play Anorm insert a scala List into a postgres text array column

放肆的年华 提交于 2020-01-04 05:37:06
问题 I'm trying to insert a List[String] into a postgresql column of type text[]. I believe when you attempt to insert any List, Anorm inserts each member of the List in its own column. I'm pretty sure this is the case because I get back the exception: org.postgresql.util.PSQLException: ERROR: INSERT has more expressions than target columns What I want to do is insert the entire List as a text[]. My current code: def insertList(listName: String, subLists: List[String]): Long = { DB.withConnection

Atomic MySQL transactions in Anorm

走远了吗. 提交于 2020-01-03 16:05:32
问题 I have written a simple hit counter, that updates a MySQL database table using Anorm. I want the transaction to be atomic. I think that the best way would be to join all of the SQL strings together and do one query, but this doesn't seem to be possible with Anorm. Instead I have placed each select, update and commit on separate lines. This works but I can't help thinking that their must be a better way. private def incrementHitCounter(urlName:String) { DB.withConnection { implicit connection

Dynamic SQL Parameters with Anorm and Scala Play Framework

最后都变了- 提交于 2020-01-03 07:26:22
问题 Is it possible to dynamically create a list for anorm's "on" method? I have a form with optional inputs and currently I check each Option and create a list with the defined Options and am trying to pass this through to anorm. Currently I get this compilation error type mismatch; found : List[java.io.Serializable] required: (Any, anorm.ParameterValue[_]) I'm not sure how I would go about creating this list. Current code : val onList = List( 'school_id = input.school, if(input.rooms isDefined)

Inserting multiple values into table with anorm

岁酱吖の 提交于 2020-01-02 05:54:07
问题 I want to insert multiple values into a table from a SQL query in Anorm. In the following snippet, is there a way to bind a list of usernames as values instead of just one username? SQL("insert into users (username) " + "values ({username})").on( 'username -> username, ).executeUpdate() As an alternative, I can create a concatenated string from my inputs, but that's prone to SQL injection and isn't quite as clean. 回答1: A possible way to insert multiple values at once, using Anorm: var fields:

Play2's anorm can't work on postgresql

北战南征 提交于 2020-01-01 01:44:06
问题 I found that the row parsers of play2's anorm depend on the meta data returned by jdbc driver. So in the built-in sample "zentasks" provided by play, I can find such code: object Project { val simple = { get[Pk[Long]]("project.id") ~ get[String]("project.folder") ~ get[String]("project.name") map { case id~folder~name => Project(id, folder, name) } } } Please notice that the fields all have a project. prefix. It works well on h2 database, but not on postgresql. If I use portgresql, I should

Scala Play 2.3.0 with Anorm - Can't use Pattern Matching (IntelliJ cannot resolve symbol Row)

ぐ巨炮叔叔 提交于 2019-12-31 07:09:10
问题 I am developing an application with Scala (2.11) and Play Framework (2.3.0) on IntelliJ IDEA. I'm using Anorm to retrieve data from my database (MySQL with MariaDB). Here is my first test application (it works): package controllers import play.api.mvc._ import play.api.db._ import anorm._ case class Client(id: Int, nom: String, prenom: String) object Application extends Controller { def index = Action { var result: List[(Int, String)] = List() val sqlQuery = SQL( """ select idClient,