anorm

anorm joda-time - localdatetime support

本秂侑毒 提交于 2019-12-08 07:00:45
问题 With Anorm 2.5.2 SQL(s"insert into user (name, registered_date) values ({name},{registered_date})").on( 'name -> user.name, 'registered_date -> user.registeredDate ).executeInsert() Compilation error: Error:(72, 24) type mismatch; found : (Symbol, org.joda.time.LocalDateTime) required: anorm.NamedParameter 'registered_date -> user.registeredDate Should I include some implicit Time->Row transformation or it should come out of the box with anorm? where user: case class User(id: Option[Long] =

Anorm 2.3 multi-value parameter: required anorm.NamedParameter

时光怂恿深爱的人放手 提交于 2019-12-08 05:48:31
问题 Using scala 2.11.1 on play framework 2.3. Because Anorm didn't support multi-value parameters in previous versions I used David's workaround. Anorm now supports multi-value parameters and I started removing the workaround and using Anorm multi-value parameters. The example [sic] mentioned: // With default formatting (", " as separator) SQL("SELECT * FROM Test WHERE cat IN ({categories})"). on('categories -> Seq("a", "b", "c") // -> SELECT * FROM Test WHERE cat IN ('a', 'b', 'c') Yet my code:

Play2 and Anorm, how do I make the One in a One to Many relationship aware of it's Manys

孤者浪人 提交于 2019-12-08 02:21:49
问题 I have a one to many relationship between User and LinkedAccount, a User can have several linked accounts. I have no problem in loading a LinkedAccount and it's User by doing: LinkedAccount(id, provider_user_id, salt, provider_id, auth_method, avatar_url, User.findBy(user)) in the parser. What I can't figure out is how load a user with it's LinkedAccounts. I guess I need to make the user aware of the LinkedAccounts.. but how? I would like to this to get rid of one extra sql call to the db

Play Framework Anorm & DB Not Reseolved

僤鯓⒐⒋嵵緔 提交于 2019-12-07 13:02:39
问题 I'm using the Play Framework 2.2.3 for my first time and I'm having a lot of trouble importing anorm._ and api.db.DB so I can set up my SQL databases. My set-up is this: MainController.scala import play.api._ import play.api.mvc._ import play.api.db.DB import anorm._ object MainController extends Controller {...} application.conf # db.default.driver=com.mysql.jdbc.Driver # db.default.url="jdbc:mysql:/usr/local/path/to/database" build.sbt libraryDependencies += "mysql" % "mysql-connector-java"

How to properly use Scala Play Anorm and Option[String] to insert NULL SQL

…衆ロ難τιáo~ 提交于 2019-12-07 12:51:49
问题 What is the proper way to insert Option[String] when it is None? The below code inserts an empty string, which is not the same as NULL in mysql. Is the only way to build the SQL string beforehand based on the content of partnerCode? Sigh...Anorm... DB.withConnection { implicit connection => val id: Option[Long] = SQL( """ INSERT INTO users (email, partner_code, is_active, created, pass) VALUES ({email}, {partnerCode}, 0, NOW(), {pass}) """ ).on( 'email -> user.email, 'partnerCode -> user

Inserting Json objects in PostgreSQL json fields with Anorm

梦想与她 提交于 2019-12-07 02:51:00
问题 How can I pass a JsObject into a json data type field in a PostgreSQL 9.3 database with Anorm without having to cast it as a string? Given a PostgreSQL 9.3 table such as: create table profiles ( id serial primary key, profile json null ); With Play 2.2, this test succeeds: package helpers import anorm._ import org.specs2.mutable._ import org.specs2.runner._ import org.junit.runner._ import play.api.db.DB import play.api.libs.json._ import play.api.test._ @RunWith(classOf[JUnitRunner]) class

Play2 and Anorm, how do I make the One in a One to Many relationship aware of it's Manys

扶醉桌前 提交于 2019-12-06 06:21:32
I have a one to many relationship between User and LinkedAccount, a User can have several linked accounts. I have no problem in loading a LinkedAccount and it's User by doing: LinkedAccount(id, provider_user_id, salt, provider_id, auth_method, avatar_url, User.findBy(user)) in the parser. What I can't figure out is how load a user with it's LinkedAccounts. I guess I need to make the user aware of the LinkedAccounts.. but how? I would like to this to get rid of one extra sql call to the db everytime I want to find if the user have a linked account of the given type. Currently I do like this:

How to use Anorm outside of Play?

烂漫一生 提交于 2019-12-05 23:41:15
问题 How do you use Anorm outside of play in Scala? In the Anorm document for play, it simply uses something like: DB.withConnection { implicit c => val result: Boolean = SQL("Select 1").execute() } The DB object is only for Play. How do you use Anorm alone without using Play? 回答1: There is no need of DB object (part of Play JDBC not Anorm). Anorm works as along as you provide it connection as implicit: implicit val con: java.sql.Connection = ??? // whatever you want to resolve connection SQL

How to properly use Scala Play Anorm and Option[String] to insert NULL SQL

我的梦境 提交于 2019-12-05 20:37:37
What is the proper way to insert Option[String] when it is None? The below code inserts an empty string, which is not the same as NULL in mysql. Is the only way to build the SQL string beforehand based on the content of partnerCode? Sigh...Anorm... DB.withConnection { implicit connection => val id: Option[Long] = SQL( """ INSERT INTO users (email, partner_code, is_active, created, pass) VALUES ({email}, {partnerCode}, 0, NOW(), {pass}) """ ).on( 'email -> user.email, 'partnerCode -> user.partnerCode.getOrElse(""), // FIXME: how to use NULL keyword instead of empty string? Is Anorm just this

How to handle null in Anorm

倖福魔咒の 提交于 2019-12-05 20:17:55
I have a table with nullable column, and when query the null column, it threw error val row: List[(String,String)] = SQL("select top 10 Spare_Part part,Pricing_Category cat from Price_Point_Base") .as((str("part"))~ str("cat") map(flatten) *) I checked the link https://www.playframework.com/documentation/2.0/ScalaAnorm . It only gives away to handle nullable column using something like SQL("Select name,indepYear from Country")().map { row => row[String]("name") -> row[Option[Int]]("indepYear") } But since str("part") is more compact than row[String]("name") , so I'd like to try using str("part