anorm

Play Framework Anorm & DB Not Reseolved

旧城冷巷雨未停 提交于 2019-12-05 18:50:45
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" % "5.1.27" My first question is whether or not I'm setting up MySQL database connection correctly. The

Scala Play! Using anorm or ORM

我与影子孤独终老i 提交于 2019-12-05 17:01:34
问题 It seems that all the sample applications provided by the Play! framework make use of anorm for persistence. What is the reason for choosing anorm over an ORM? If you are using an ORM, what are you using and why? 回答1: I think most of the arguments for anorm are listed on the corresponding page in the documentation. For the time being I personally prefer a Scala and Play independent data access layer, thus I am using Ebean (and would be using JPA, if it was the recommended default). Being able

Inserting multiple values into table with anorm

感情迁移 提交于 2019-12-05 14:46:25
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. A possible way to insert multiple values at once, using Anorm: var fields: List[String] = Nil var values: List[(String,ParameterValue[_])] = Nil for ((username,i) <- usernames

How to better parse the same table twice with Anorm?

十年热恋 提交于 2019-12-05 02:38:04
Suppose I have the following two classes: case class User(id: Long, name: String) case class Message(id: Long, body: String, to: User, from: User) The RowParser s might look something like this: val parser: RowParser[User] = { get[Long]("users.id") ~ get[String]("users.name") map { case id~name => User(id, name) } } val parser: RowParser[Message] = { get[Long]("messages.id") ~ get[String]("messages.name") ~ User.parser ~ User.parser map { case id~body~to~from => Message(id, body, to, from) } } Except that this won't work, because when joining the users table twice, Anorm will only parse the

Anorm parse float values

最后都变了- 提交于 2019-12-04 17:35:46
问题 In Play framework 2.0, I'm trying to load a real (i.e. single precision float) type column from PostgreSQL using a row parser like this: case class Foo(bar: Float) object Foo { def all = DB.withConnection { implicit c => SQL("SELECT * FROM foo").as(fooParser *) } val fooParser = { get[Float]("bar") map { case bar => Foo(bar) } } } This generates an error: could not find implicit value for parameter extractor: anorm.Column[Float] When using double precision types everything works fine. Is it

How to use Anorm outside of Play?

若如初见. 提交于 2019-12-04 03:54:59
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? cchantep 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"SELECT * FROM Table".as(...) You can resolve JDBC connection in many way: basic DriverManager

Scala Play! Using anorm or ORM

a 夏天 提交于 2019-12-04 02:28:23
It seems that all the sample applications provided by the Play! framework make use of anorm for persistence. What is the reason for choosing anorm over an ORM? If you are using an ORM, what are you using and why? I think most of the arguments for anorm are listed on the corresponding page in the documentation. For the time being I personally prefer a Scala and Play independent data access layer, thus I am using Ebean (and would be using JPA, if it was the recommended default). Being able to use the Models without any Play-dependencies is a huge plus, in my opinion. Also Anorm does not seem to

Anorm parse float values

青春壹個敷衍的年華 提交于 2019-12-03 11:09:37
In Play framework 2.0, I'm trying to load a real (i.e. single precision float) type column from PostgreSQL using a row parser like this: case class Foo(bar: Float) object Foo { def all = DB.withConnection { implicit c => SQL("SELECT * FROM foo").as(fooParser *) } val fooParser = { get[Float]("bar") map { case bar => Foo(bar) } } } This generates an error: could not find implicit value for parameter extractor: anorm.Column[Float] When using double precision types everything works fine. Is it somehow possible to use single precision floats with Anorm? You can always create your own column parser

Play2's anorm can't work on postgresql

余生颓废 提交于 2019-12-03 06:01:19
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 write it as: object Project { val simple = { get[Pk[Long]]("id") ~ get[String]("folder") ~ get[String](

“In” clause in anorm?

末鹿安然 提交于 2019-12-03 04:27:07
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) val paramsList = for ( i <- 0 until params.size ) yield ("userId" + i) // ---> results in List(