GithubHelp home page GithubHelp logo

playframework / play-slick Goto Github PK

View Code? Open in Web Editor NEW
800.0 47.0 283.0 1.7 MB

Slick Plugin for Play

License: Apache License 2.0

Scala 100.00%
playframework slick scala sbt-plugin database-library database-access database-access-library

play-slick's Introduction

Play Slick

Twitter Follow Discord GitHub Discussions StackOverflow YouTube Twitch Status OpenCollective

Build Status Maven Repository size Scala Steward badge Mergify Status

The Play Slick module makes Slick a first-class citizen of Play. It consists of two features:

  • Integration of Slick into Play's application lifecycle.
  • Support for Play database evolutions.

Because Slick creates and manages both a connection pool and a thread pool, integrating Slick with Play boils down to ensuring that all resources allocated by Slick are shutdown when a Play application is stopped (or reloaded).

The plugin has its own release cycle and therefore is not integrated into either core Play or Slick.

Examples of play-slicks usage can be found here.

Current Version

To use play-slick, you need to add the following dependencies:

libraryDependencies ++= Seq(
  "org.playframework" %% "play-slick" % "6.1.0",
  "org.playframework" %% "play-slick-evolutions" % "6.1.0"
)

Or use a version that is compatible with the Play version you are using. See all available versions below.

All Releases

The Play Slick plugin supports several different versions of Play and Slick.

Plugin version Play version Slick version Scala version
6.1.x 3.0.0 3.5.0+ 2.13.x/3.3.x
5.3.x 2.9.0 3.5.0+ 2.13.x/3.3.x
6.0.x 3.0.0 3.4.1 2.13.x
5.2.x 2.9.0 3.4.1 2.13.x
5.1.x 2.8.16 3.4.1+ 2.12.x/2.13.x
5.0.x 2.8.x 3.3.2+ 2.12.x/2.13.x
4.0.2+ 2.7.x 3.3.2+ 2.11.x/2.12.x/2.13.x
4.0.x 2.7.x 3.3.x 2.11.x/2.12.x
3.0.x 2.6.x 3.2.x 2.11.x/2.12.x
2.1.x 2.5.x 3.2.0 2.11.x
2.0.x 2.5.x 3.1.0 2.11.x
1.1.x 2.4.x 3.1.0 2.10.x/2.11.x
1.0.1 2.4.x 3.0.1 2.10.x/2.11.x
1.0.0 2.4.x 3.0.0 2.10.x/2.11.x
0.8.x 2.3.x 2.1.0 2.10.x/2.11.x
0.7.0 2.3.x 2.0.2 2.10.x
0.6.1 2.2.x 2.0.x 2.10.x
0.5.1 2.2.x 1.0.x 2.10.x
  • Release Candidate: these releases are not stable and should not be used in production.

Note that the + next to a version means that the specified version and later trailing point releases are supported by the same version of the play-slick plugin. While a x means that any trailing point release is supported by the same version of play-slick.

Documentation

The documentation for the latest release is available here.

Releasing a new version

See https://github.com/playframework/.github/blob/main/RELEASING.md

Copyright

License: Apache License 2.0, http://www.apache.org/licenses/LICENSE-2.0.html

play-slick's People

Contributors

aaabramov avatar bancek avatar billyautrey avatar cvogt avatar dotta avatar dwijnand avatar freekh avatar gmethvin avatar guersam avatar ignasi35 avatar ihostage avatar jroper avatar loicdescotte avatar marcospereira avatar mergify[bot] avatar mkurz avatar ms-tg avatar nremond avatar octonato avatar prakhunov avatar pvlugter avatar raboof avatar richdougherty avatar safespeed avatar scala-steward avatar shreyharia avatar tototoshi avatar v6ak avatar wsargent avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

play-slick's Issues

Possible incompatibility with MS SQL Server JTDS

This plugin worked great with MySQL, but the change to MSSQL(with jtds) broke my application. I now get a [RuntimeException: java.lang.ExceptionInInitializerError] whenever I try to access my db. The bottom of my stack trace says

Caused by: play.api.Configuration$$anon$1: Configuration error[Slick error : Unknown jdbc driver found in application.conf: [net.sourceforge.jtds.jdbc.Driver]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:80) ~[play_2.10.jar:2.1.1]
    at play.api.Configuration.reportError(Configuration.scala:558) ~[play_2.10.jar:2.1.1]
    at play.api.db.slick.Config$.driver(Config.scala:21) ~[play-slick_2.10-0.3.3.jar:0.3.3]
    at play.api.db.slick.Config$.driver$lzycompute(Config.scala:7) ~[play-slick_2.10-0.3.3.jar:0.3.3]
    at play.api.db.slick.Config$.driver(Config.scala:7) ~[play-slick_2.10-0.3.3.jar:0.3.3]

Using version 0.3.3 of the plugin.

More info here

Doc update

Hi @freekh
I will try to improve the documentation of the plugin.
Do you think it would be ok to add a part with "default configuration datasource" , i.e. using directly the import from the Config object, in addition to the multi driver/cake pattern section?

I will also add some parts about the way to test the app with a test datasource.

Thanks
Loïc

Not playing nice with Eclipse

When I create a project and follow the directions to add a dependency of play-slick via .dependsOn(RootProject( uri("git://github.com/freekh/play-slick.git") )) and then I run eclipse to create an eclipse project, there are a few issues.
First, the eclipse command says that it created eclipse project files for my project and for the play-slick project, as well. However, when I import the project into Eclipse it only finds the project files for my project, not for the play-eclipse project, so it complains that there are errors in the build path. If I remove the reference to the play-slick project in the build path, that error is resolved but a different error remains: The project cannot be built until build path errors are resolved.
I am using scala-ide with Eclipse Juno. Is there some simple configuration step I'm missing to get a play-slick project imported into Eclipse correctly? Or is there a different method that I should be using to import my project into Eclipse? With other dependencies I simply add maven artifacts to the Build.scala and everything works beautifully. When play-slick has matured, will it be available via the Maven repo, also?

I should mention this is purely an issue for Eclipse. The project itself runs fine (except for the issue I wrote about in my other pull request).

cannot use cake pattern with lazy members

If I have a lazy val and try to use it like this:

class DAO(override val profile: ExtendedProfile) extends CatComponent with Profile

object current {
  lazy val dao = new DAO(slick.driver.H2Driver)
}

application.conf looks like this: slick.default="models.current.dao.*"

DB.driver returns the driver for the default database

for example:

object SomeDb {
  import play.api.db.slick.DB

  val db = DB.database("some")
  // db.driver() will return the driver for the db.defult, not db.some
  val dao = new SomeDAO(db.driver(play.api.Play.current))
}

This is somewhat unexpected and makes it hard to connect to different databases from the same application, when using the pattern described in the README to keep the code independent of the actual drivers.

I'm guessing that this could be fixed by adding a name parameter to Config.driver(app) and passing DB.CurrentDB to the method. Should I send a pull request with this change?

UnexpectedException: Unexpected exception[ExceptionInInitializerError: null]

I get play.api.UnexpectedException: Unexpected exception[ExceptionInInitializerError: null] after play new, adding slick.default="models.*" to application.conf and creating the model:

package models

import play.api.db.slick.Config.driver._

case class Cat(name: String, color: String)

object Cats extends Table[Cat]("CAT") {

  def name = column[String]("name", O.PrimaryKey)
  def color = column[String]("color", O.NotNull)

  def * = name ~ color <> (Cat.apply _, Cat.unapply _)
}

support for slick-extensions

I might be missing something, but I'm getting this error when trying to access an Oracle database using the slick-extensions. (The ojdbc14.jar files in the lib directory.)

play.api.Configuration$$anon$1: Configuration error[Slick error : Unknown jdbc driver found in application.conf: [oracle.jdbc.driver.OracleDriver]]

Need to refactor DBAction

Several problems need to be fixed around DBAction :

  1. Use SimpleResult and Action.async to avoid Play 2.2 warnings
[warn] play-slick/src/main/scala/play/api/db/slick/package.scala:42: trait Result in package mvc is deprecated: Result will become SimpleResult in Play 2.3
[warn]     def apply(r: (RequestWithDbSession) => Result)(implicit app:Application) = {
[warn]                                         ^
[warn] play-slick/src/main/scala/play/api/db/slick/package.scala:44: class AsyncResult in package mvc is deprecated: Use Future[SimpleResult] with Action.async action builder instead. Will be removed in Play 2.3.
[warn]         AsyncResult {
  1. Future should wrap all the action/session : http://stackoverflow.com/questions/18579684/play-slick-and-async-is-it-a-race-condition

  2. DBAction should be able to take a database name parameter (see #78)

DBAction not found?

Hey folks,

I was getting a compile error "not found: value DBAction" when trying to migrate my anorm-based sample project to slick. At first I assumed I'd made a configuration error, so I tried again, this time using a fresh checkout of computer-database sample.

The computer-database project works fine without any changes, however when the Build.scala is altered to remove the dependency on the RootProject and "com.typesafe.play" %% "play-slick" % "0.3.3" added instead as an appDependency, I get the same compile error.

Most likely a newbie error, but perhaps someone wiser than me may be able to help..

Many thanks,
-dan

Avoid objects in static locations / improvements SlickDDLPlugin

The Slick documentation should be clearer on this, but having singleton objects in static locations extend Table[...] is buggy. This is done e.g. in https://github.com/freekh/play-slick/blob/f513fdab1031de3991689afa334d175411484c78/samples/play-slick-sample/app/models/Cat.scala . It works if you do not use certain Slick features, but it does not work in the general case, because Slick clones the object under the hood and then stumbles over https://issues.scala-lang.org/browse/SI-3764 if they are defined in a static location. Instead we recommend either putting them in a trait or class or using the pattern

val SomeTable = new SomeTable
class SomeTable extends Table[ ... ]

The SlickDDLPlugin does not work with the val version, as it assumes static objects. Even worse, it did not tell me it does not support this when I switched from object to val, but just re-used the old sql-script under the hood. This lead me to committing broken versions until I changed the tables in an incompatible way that lead to exceptions in certain queries.

The SlickDDLPlugin could be fixed in these regards, but I propose a more radical change. In my opinion the reflection based table object discovery the SlickDDLPlugin does is too magical, hard to explain, debug and get right. How about using an ordinary Scala interface instead? Like a method you call, which you give a Seq of table objects? Then we could remove all the reflection magic I suppose.

DDL generation is random and crashes (MySQL)

I have migrated my DB access to use slick. However the DDL generated is inconsistent for my models package : each time I access the application via a browser, it wants to apply an DDL update to change the order in which the tables are created.

The application is completely unusable now !

The code to reproduce the issue (only the models) is in this public gist : https://gist.github.com/tyrcho/5086544

SlickDDLPlugin discover classes / fail if found nothing

The SlickDDLPlugin should be changed to discover classes from packages, so that the recommended usage of Slick is supported, where you define table objects like this:

val SomeTable = new SomeTable
class SomeTable extends Table[ ... ]

If the plugin is activated but does not find anything it should fail visibly to avoid silent reusing of outdated evolution scripts.

Additionally we should document the purpose of the plugin, i.e. that is only meant for rapid prototyping and getting started, not for longer term development.

Can't use test database

Hi

I'm using play-slick in my Play application.
When running test, my test configuration does not work.

Could you tell me how to fix the problem or could you add some tests specified to use test database into sample app?

application.conf

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=sa
db.default.password=""

test.db.default.driver=com.mysql.jdbc.Driver
test.db.default.url="jdbc:mysql://localhost/play_test"
test.db.default.user=test_user
test.db.default.password=test_user_pass

SlickTest

import org.specs2.mutable.Specification
import play.api.test.Helpers._
import play.api.test.FakeApplication
import play.api.db.slick.Config.driver.simple._
import play.api.db.slick.DB


import models.{Cat, Cats}

class SlickSpec extends Specification {

  // This test should pass, but uses `db.default.driver`
  // How can I use `test.db.default` ?
  "Slick" should {
    "insert object into test database" in {
      running(FakeApplication()) {
        import play.api.Play.current

        DB.withSession { implicit session =>
          val cat = Cat("name", "color")
          Cats.insert(cat)
        }

         DB.withSession { implicit session =>
          val count = Query((for (c <- Query(Cats)) yield c.id).countDistinct).first
          count must beEqualTo(1)
        }     
      }
    }
  }

}

Avoid table objects in static locations

The Slick documentation should be clearer on this, but having singleton objects in static locations extend Table[...] is buggy. This is done e.g. in https://github.com/freekh/play-slick/blob/f513fdab1031de3991689afa334d175411484c78/samples/play-slick-sample/app/models/Cat.scala . It works if you do not use certain Slick features, but it does not work in the general case, because Slick clones the object under the hood and then stumbles over https://issues.scala-lang.org/browse/SI-3764 if they are defined in a static location. Instead we recommend either putting them in a trait or class or using the pattern

val SomeTable = new SomeTable
class SomeTable extends Table[ ... ]

It could be fixed along the lines of cvogt@74899b4

Migrate to Play 2.1.0 final

Hi

After upgrading our project to the just released play 2.1.0 version our build is broken due to this plugins dependency on play-2.1-RC4

Thanks
Steffen

Slick-play is incompatible with log4jdbc.

When using log4jdbc in order to log SQL queries, you have to change the driver to the log4jdbc proxy : net.sf.log4jdbc.DriverSpy. That driver isn't recognized by the extension and thus crashes.

null is thrown during a Table initialization

Continued from discussion on: slick/slick#158

Looks like play-slick is being used without having a started Play application.
Typically this will not happen unless you are using are calling play-slick:

  1. in tests. If this is the case, you should make sure that you are using the WithApplication as described here: http://www.playframework.com/documentation/2.1.1/ScalaTest
  2. another library dependent on this code. If this is the case, we will have to look further into this. It would be interesting to know a bit more about the code around the area where you actually are calling the DB.withSession...

NOTE: I will be on vacation (offline) soon.

sbt dependency resolving

I get following not resolved dependency:
[warn] ==== github repo for play-slick: tried

Shortened Build.sbt is:
import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

val appName = "platform"
val appVersion = "1.0"

val appDependencies = Seq(
javaJdbc,
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"com.typesafe.slick" % "slick_2.10" % "1.0.0",
"com.typesafe" % "play-slick_2.10" % "0.3.0")

val main = play.Project(appName, appVersion, appDependencies).settings(
resolvers := Seq(
Resolver.url("github repo for play-slick", url("http://loicdescotte.github.com/releases/")))
}

Sample app

This plugin seems very interesting.
Do you have a sample app using it?
It would be cool to have some examples, especially about (multi) driver management.

Thanks

Evolutions file not created when 1.sql exists

play-slick only creates an evolutions file for you if you don't have one yet. That's what you want when you first create your model, but doesn't allow you to use this feature when you later change your model and need to create a 2.sql, perhaps with a new table.

Suggestion: instead of generating 1.sql if it isn't there, generate create.sql and drop.sql unless a configuration parameter is set to false. Then you can write your 2.sql based on the diff between 1.sql and create.sql.

I can also imagine situations on a project where you want to run the whole create or drop script on a test database.

Wrong MySQL driver class name

The correct class should be
db.default.driver=com.mysql.jdbc.Driver

but the Config seems to expect "com.mysql.Driver" for mysql and since I also use anorm there is a conflict where or anorm (correctly) or slick complains about the driver.

You might also want to update the error message as below, currently the user has to browse the source to find out what is supported:

java.lang.RuntimeException: Unknown driver [valueenteredinconfig], supported drivers are [x, y, z, ...]

can't delete record

I am use play + play-slick-0.3.2 + slick 1.0.0

add import play.api.db.slick.Config.driver.simple._

I write follow statement to delete one db record:
EmpDepartments.where(ed => (ed.empId is it) && ed.endDate.isNull).delete
the compiler say:
value delete is
not a member of scala.slick.lifted.Query[models.EmpDepartments.type,scala.slick
.lifted.NothingContainer#TableNothing]
when I change to
Query(EmpDepartments.where(ed => (ed.empId is it) && ed.endDate.isNull)).delete
compile error change to:
Don't know how
to unpack scala.slick.lifted.Query[models.EmpDepartments.type,scala.slick.lifted
.NothingContainer#TableNothing] to U and pack to R

Very strange, sometimes compile is ok and run result also ok. finally, i replace it with NativeQuery, I really like scala style query or update, i don't know this is a issue about play-slick or slick even or scala.

When using from remote dependency, the jar is missing classes.

Great work making Slick work on Play. However, I think I've spotted an easy fix.

It appears that the jar file that is downloaded when you add the dependency to the build.scala file is missing a few classes.

If download the latest from GitHub I can see the package
play.api.db.slick

  • Config.scala
  • DB.scala
  • Profile.scala
  • session.scala
  • SlickExecutionContext.scala
  • SlickPlugin.scala

However, if I inspect the jar that is downloaded when I run eclipse (using the eclipse command) I see the following jar and package:
play-slick_2.10-0.3.3.jar
play.api.db.slick

  • Config.class
  • DB.class
  • Profile.class
  • ReflectionUtils.class
  • SlickDDLPlugin.class

Hence, I get compile errors when I try and use the session class from within my app. This error doesn't happen in the sample. app that doesn't use the remote dependency.

Snapshot releases

The latest stable release of this plugin is 0.3.3, yet all the cool DBAction stuff seems to be happening in master. Would it be possible to get a snapshot release somewhere, or is it perhaps already available? (didn't see where from the build.sbt definition)

make documentation on DDL clearer

Currently, the doc is not explicit about the benefits of DDL creation. Should also specify in which uses cases you should not use DDL creation.

testing fails if run mulitple times

If tests are run multiple times using the DB wrapper, this type of error will start happening:

[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 1. Exception: null
[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08001

I believe it is linked to the way DataSources are created in Play and in Slick.

For a cleaner model, I think I will try to just wrap a Session in the connection from the Play DataSource directly

No oracle support

I'm trying to use play-slick over slick-extenions' Oracle support to no avail... apparently a reference to oracle.jdbc.OracleDriver is needed in the hard-coded map play.api.db.slick.Database.driverByName of jdbc driver's class name to slick driver. ¿Really?...

Not able to use threadLocalSession

Hi,

With "play.api.db.slick.DB" import, we can't use threadLocalSession .

Example :

With

import play.api.db.slick.DB
import scala.slick.session.Database.threadLocalSession

 DB.withSession { 
       Todos.insert("test", "a test")
       val q = for {
         t <- Todos
 } yield (t.name, t.desc)

We have this error :

Overloaded method value [withSession] cannot be applied to (...) (*)

But this way it's working :

import play.api.db.DB
import scala.slick.session.Database
import scala.slick.session.Database.threadLocalSession

lazy val database = Database.forDataSource(DB.getDataSource())

 DB.withSession { 
  ....   
}

threadLocalSession is cool because il allows to write

DB.withSession { 
   ...
}

instead of

DB.withSession { implicit session =>
 ... 
} 

It can be useful to reduce verbosity if we have a lot of "DB.withSession " blocks

(*) Unit in this case but coud be any type

Dependencies not resolving

I have added typesafe repo event then it is throwing error.. using play 2.1.1, sbt 0.12.2 scala 2.10.

[warn] module not found: com.typesafe.play#play-slick;0.3.2
[warn] ==== Typesafe Releases Repository: tried
[warn] http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-slick/0.3.2/play-slick-0.3.2.pom
[warn] ==== Typesafe Snapshots Repository: tried
[warn] http://repo.typesafe.com/typesafe/snapshots/com/typesafe/play/play-slick/0.3.2/play-slick-0.3.2.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/com/typesafe/play/play-slick/0.3.2/play-slick-0.3.2.pom
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.play#play-slick;0.3.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: com.typesafe.play#play-slick;0.3.2: not found

TestServer makes DB Pool fail

I am not sure if this is related to Slick or not but if I have several tests and one looks like this:

package test

import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._

/**
 * add your integration spec here.
 * An integration test will fire up a whole play application in a real (or headless) browser
 */
class IntegrationSpec extends Specification {

  "Application" should {

    "work from within a browser" in {
      running(TestServer(3333), HTMLUNIT) { browser =>

        browser.goTo("http://localhost:3333/")
        true
      }
    }

  }

}

It fails with:

play.api.Application$$anon$1: Execution exception[[SQLException: Attempting to obtain a connection from a pool that has already been shutdown. 
Stack trace of location where pool was shutdown follows:
 java.lang.Thread.getStackTrace(Thread.java:1503)
 com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:543)
 com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:159)
 com.jolbox.bonecp.BoneCPDataSource.close(BoneCPDataSource.java:123)
 play.api.db.BoneCPApi.shutdownPool(DB.scala:405)
 play.api.db.BoneCPPlugin$$anonfun$onStop$1.liftedTree1$1(DB.scala:263)
 play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:262)
 play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:261)
 scala.collection.immutable.List.foreach(List.scala:309)
 play.api.db.BoneCPPlugin.onStop(DB.scala:261)
 play.api.Play$$anonfun$stop$1$$anonfun$apply$1$$anonfun$apply$mcV$sp$2.apply(Play.scala:80)
 play.api.Play$$anonfun$stop$1$$anonfun$apply$1$$anonfun$apply$mcV$sp$2.apply(Play.scala:79)
 scala.collection.immutable.List.foreach(List.scala:309)
 play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply$mcV$sp(Play.scala:79)
 play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply(Play.scala:79)
 play.api.Play$$anonfun$stop$1$$anonfun$apply$1.apply(Play.scala:79)
 play.utils.Threads$.withContextClassLoader(Threads.scala:18)
 play.api.Play$$anonfun$stop$1.apply(Play.scala:78)
 play.api.Play$$anonfun$stop$1.apply(Play.scala:77)
 scala.Option.map(Option.scala:145)
 play.api.Play$.stop(Play.scala:77)
 play.api.test.Helpers$.running(Helpers.scala:42)
 test.ApplicationSpec$$anonfun$1$$anonfun$apply$7.apply(ApplicationSpec.scala:24)

request.body not accessible when using DBAction

I have a controller for POST method. When DBAction is used, the request.body is not accessible. The error goes away when i switch to the normal Action

value body is not a member of play.api.db.slick.RequestWithDbSession
[error]     request.body.asJson.map { json =>
[error]             ^

The relevant code snippet is

def submit = DBAction { implicit request=>
    request.body.asJson.map {...}
}

I could reproduce this issue in the computer-database sample app, by adding rs.body in the Application::Update action

Use a different session for tests

In tests it is possible to use different DB.session , for example :

      DB("test").withSession { implicit session =>
          // my test query
        }     

The loaded datasource will be the one defined with db.test.* in application.conf.

This is fine, but If you want to test some controllers or models that use DB.withSession (and not DB("test").withSession ) you will be binded to the default datasource, not to the test datasource.

Maybe it will be solved in the same time that #14 with the session wrapping, but I add the issue for reminder.

Evolutions not being applied

To preface, this is probably a mistake on my part.
I'm using com.microsoft.sqlserver.jdbc.SQLServerDriver. Just as a test I created a brand new empty database, and I have only one mapped Object in my models package. When I attempt to access the application, I get the expected error Database 'default' needs evolution!, and the proper evolution sql is generated. When I click Apply this script now!, the play_evolutions table is created, but the evolution itself doesn't actually get applied. A table should be created, but it is not, and there are no entries in the play_evolutions table. Consequently, the error page Database 'default' needs evolution! continues to display on refresh.

I verified that the user indeed had the proper privileges to create the table by running the sql as that user in my SQL Server Management Studio, and it went off without a hitch. There are no other errors in the console/logs (just the one about the evolution needing to be applied).
Any thoughts? Are there known issues with the microsoft jdbc driver? As an aside, I would prefer to use jTDS but it doesn't look like it's supported by play-slick. Is there any plan to add support for jtds?

Thanks.

play-slick requires tables to be defined statically

Slick explicitly states that you should not use a static location for your Table definitions:

Also make sure that an actual object for a table is not defined in a static location (i.e. at the top level or nested only inside other objects) because this can cause problems in certain situations due to an overeager optimization performed by scalac. Using a val for your table (with an anonymous structural type or a separate class definition) is fine everywhere.

However, play-slick seems only to recognise Table definitions is they are defined statically - trying to define them through a val in a package object results in the following:

ReflectError: value ParameterTypes is not a package

Not driver specific model

Hey,

I made a little example a few weeks ago on how to integrate Slick with Play2. My example uses Cake Pattern and driver configuration via application.conf of Play, so that when you create a Table class, you don't have to create this for a certain Slick driver, but you can create this for any, and then you can configure this in the application.conf

Take a look at https://github.com/mgonto/slick-play2-example specifically https://github.com/mgonto/slick-play2-example/blob/master/app/models/DBeable.scala and let me know if you want to include this to the plugin. I can give you a hand on doing so.

threadLocalSession can not be used within a withSession block

similar to #15 but I have a different error message

Action { request =>
  play.api.db.slick.DB.withSession{ implicit session =>
    Logger.info(slick.session.Database.threadLocalSession.toString)
    Ok
  }
}

this gives me:

SQLException: No implicit session available; threadLocalSession can only be used within a withSession block

Am I missing something or is this a bug?

improve documentation

IMHO, the docs should explain only play-slick specifics like DBAction with Request and Session. For everything about Slick in general we should reference the Slick docs. This includes patterns for common use cases like cake, query libraries, daos, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.