Skip to content

Instantly share code, notes, and snippets.

@mslinn
Last active December 10, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mslinn/4465678 to your computer and use it in GitHub Desktop.
Save mslinn/4465678 to your computer and use it in GitHub Desktop.
Play Anorm code that DOES insert >22 columns into a database, using Play 2.1 and Scala 2.10-RC5. I built Play 2.1 against Scala 2.10-RC5 using my fork of the project.
package com.micronautics.paypal
import play.api.db.DB
import anorm._
import play.api.Play.current
object AnormTest {
DB.withConnection { implicit connection =>
val sql = SQL(
"""insert into paypal_transaction(
| addressName, firstName, lastName, payerEmail, street, city, state, zipCode, memo,
| paymentDate, paymentType, txnId, mcGross, mcFee, paymentStatus, pendingReason, tax,
| mcCurrency, reasonCode, custom, country, payerId, verifySign, getsUpdates, receiver_email, is_complementary
| ) values (
| {addressName}, {firstName}, {lastName}, {payerEmail}, {street}, {city}, {state}, {zipCode}, {memo},
| {paymentDate}, {paymentType}, {txnId}, {mcGross}, {mcFee}, {paymentStatus}, {pendingReason}, {tax},
| {mcCurrency}, {reasonCode}, {custom}, {country}, {payerId}, {verifySign}, {getsUpdates}, {receiver_email},
| {is_complementary}
| )""".stripMargin).on(
'addressName -> "addressName", 'firstName ->"firstName", 'lastName -> "lastName",
'payerEmail -> "payerEmail", 'street -> "street", 'city -> "city", 'state -> "CA", 'zipCode -> "zipCode",
'memo -> "memo", 'paymentDate -> new java.sql.Date(0), 'paymentType-> "paymentType", 'txnId -> "txnId",
'mcGross -> "mcGros", 'mcFee -> "mcFee", 'paymentStatus -> "paymentStatus",
'pendingReason -> "pendingRea", 'tax -> "tax", 'mcCurrency -> "mcCur", 'reasonCode -> "reasonCode",
'custom -> "custom", 'country -> "country", 'payerId -> "payerId", 'verifySign -> "verifySign",
'getsUpdates -> true, 'receiver_email -> "receiver@email.com", 'is_complementary -> true
)
val id: Option[Long] = sql.executeInsert()
println(s"Inserted record with id=$id into PaypalTransaction")
}
}
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "blah"
val appVersion = "0.1.0"
scalaVersion := "2.10.0-RC5"
val appDependencies = Seq(
"ch.qos.logback" % "logback-classic" % "1.0.9" withSources(),
"mysql" % "mysql-connector-java" % "5.1.21",
"play" % "anorm_2.10" % "2.1-SNAPSHOT" withSources(),
"play" %% "play-jdbc" % "2.1-SNAPSHOT" withSources()
)
scalacOptions ++= Seq("-deprecation", "-encoding", "UTF-8", "-feature", "-target:jvm-1.6", "-unchecked", "-Ywarn-adapted-args")
val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers += Resolver.file("Local Repository", file("e:/work/experiments/scala/Play20/repository/local"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("sbt-plugin-snapshots", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots/"))(Resolver.ivyStylePatterns)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment