本文整理汇总了Scala中play.api.db.evolutions.Evolutions类的典型用法代码示例。如果您正苦于以下问题:Scala Evolutions类的具体用法?Scala Evolutions怎么用?Scala Evolutions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Evolutions类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: PlayWithFoodWithTestComponents
//设置package包名称以及导入依赖的类
package testhelpers
import config.ExampleComponents
import org.scalatest.BeforeAndAfterEach
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.components.OneServerPerTestWithComponents
import play.api.db.evolutions.Evolutions
import play.api.http.Status
import play.api.libs.ws.WSClient
import play.api.test.{DefaultAwaitTimeout, FutureAwaits, Helpers, TestServer}
import play.api.{Application, Configuration}
import slick.dbio.DBIO
trait PlayWithFoodWithServerBaseTest extends PlaySpec
with OneServerPerTestWithComponents
with DefaultFutureDuration
with DefaultExecutionContext
with Status
with DefaultAwaitTimeout
with FutureAwaits
with BeforeAndAfterEach {
class PlayWithFoodWithTestComponents extends ExampleComponents(context) {
override def configuration: Configuration = {
val testConfig = Configuration.from(TestUtils.config)
val config = super.configuration
val testConfigMerged = config ++ testConfig
config.toString
testConfigMerged
}
implicit lazy val testWsClient: WSClient = wsClient
}
override def components: PlayWithFoodWithTestComponents = new PlayWithFoodWithTestComponents
private def runServerAndCleanUpInMemDb(c: PlayWithFoodWithTestComponents) = {
runServerAndExecute(c.application) {
val dbapi = c.dbApi
Evolutions.cleanupEvolutions(dbapi.database("default"))
}
}
override protected def afterEach(): Unit = {
runServerAndCleanUpInMemDb(components)
}
protected def runServerAndExecute[T](app: Application)(blockWithComponents: => T): T = {
Helpers.running(TestServer(port, app))(blockWithComponents)
}
def runAndAwaitResult[T](action: DBIO[T])(implicit components: ExampleComponents): T = {
TestUtils.runAndAwaitResult(action)(components.actionRunner, duration)
}
}
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:58,代码来源:PlayWithFoodWithServerBaseTest.scala
示例2: AppLoader
//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource
import controllers.UsersController
import io.getquill._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.evolutions.Evolutions
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.api.routing.sird._
import models.{Users}
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = new BuiltInComponentsFromContext(context) with DBComponents with HikariCPComponents {
lazy val db = new H2JdbcContext[SnakeCase](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])
lazy val users = new Users(db)
lazy val usersController = new UsersController(users)
val router = Router.from {
case GET(p"/users/${long(id)}") => usersController.get(id)
case POST(p"/users") => usersController.create
case DELETE(p"/users/${long(id)}") => usersController.delete(id)
case PUT(p"/users/${long(id)}") => usersController.update(id)
}
override lazy val injector: Injector =
new SimpleInjector(NewInstanceInjector) + users + router + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + global
Evolutions.applyEvolutions(dbApi.database("default"))
}.application
}
开发者ID:getquill,项目名称:play-quill-jdbc,代码行数:38,代码来源:AppLoader.scala
示例3: TodoRepositoryTest
//设置package包名称以及导入依赖的类
package repositories
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{MustMatchers, WordSpec}
import play.api.db.evolutions.Evolutions
import play.api.db.{Database, Databases}
class TodoRepositoryTest extends WordSpec
with ScalaFutures
with MustMatchers {
def withMyDatabase[T](block: Database => T) = {
Databases.withInMemory(
name = "default",
urlOptions = Map(
"MODE" -> "PostgreSQL"
),
config = Map(
"logStatements" -> true
)
)(block)
}
def withRepo[T](block: TodoRepository => T) = withMyDatabase { db =>
Evolutions.applyEvolutions(db)
block(new TodoRepository(db))
}
"TodoRepository#getAllTodos" when {
"has no TODOs" should {
"return empty" in withRepo { repo =>
whenReady(repo.getAllTodos, timeout(Span(6, Seconds))) { result =>
result mustBe empty
}
}
}
}
}
开发者ID:cosmetica,项目名称:TODO_play_scala,代码行数:40,代码来源:TodoRepositoryTest.scala
示例4: runEvolution
//设置package包名称以及导入依赖的类
package repository
import play.api.db.Databases
import play.api.db.evolutions.Evolutions
trait DatabaseEvolution {
val database = Databases(
driver = "org.h2.Driver",
url = "jdbc:h2:mem:caradverttest"
)
def runEvolution(): Unit = {
Evolutions.applyEvolutions(database)
database.withConnection(connection => {
val stmt = connection.createStatement()
stmt.execute("TRUNCATE TABLE caradvert")
})
}
}
开发者ID:jogoes,项目名称:caradverts,代码行数:23,代码来源:DatabaseEvolution.scala
示例5: AppLoader
//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource
import controllers.EventsController
import controllers.UsersController
import io.getquill._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.evolutions.Evolutions
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.api.routing.sird._
import models.{Events, Users}
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = new BuiltInComponentsFromContext(context) with DBComponents with HikariCPComponents {
lazy val db = new JdbcContext[H2Dialect, SnakeCase](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])
lazy val users = new Users(db)
lazy val events = new Events(db)
lazy val usersController = new UsersController(users)
lazy val eventsController = new EventsController(events)
val router = Router.from {
case GET(p"/users/${long(id)}") => usersController.get(id)
case POST(p"/users") => usersController.create
case DELETE(p"/users/${long(id)}") => usersController.delete(id)
case PUT(p"/users/${long(id)}") => usersController.update(id)
// Events Routes
case POST(p"/events") => eventsController.push
case GET(p"/events/${long(id)}") => eventsController.get(id)
}
override lazy val injector: Injector =
new SimpleInjector(NewInstanceInjector) + users + events + router + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + global
Evolutions.applyEvolutions(dbApi.database("default"))
}.application
}
开发者ID:a605269,项目名称:play-multitenant,代码行数:45,代码来源:AppLoader.scala
示例6: beforeEach
//设置package包名称以及导入依赖的类
package com.h3poteto.ayanerer.test
import javax.inject._
import org.scalatestplus.play._
import org.scalatest._
import play.api._
import play.api.test._
import play.api.test.Helpers._
import play.api.inject.guice._
import play.api.db.{ Database, DBApi}
import play.api.db.evolutions.Evolutions
trait DatabaseSpec extends PlaySpec with OneAppPerSuite with BeforeAndAfterEach {
implicit override lazy val app: Application = new GuiceApplicationBuilder().build
// Prepare and clean database
// http://stackoverflow.com/questions/33392905/how-to-apply-manually-evolutions-in-tests-with-slick-and-play-2-4
lazy val injector = app.injector
lazy val databaseApi = injector.instanceOf[DBApi] //here is the important line
override def beforeEach() = {
Evolutions.applyEvolutions(databaseApi.database("default"))
}
override def afterEach() = {
Evolutions.cleanupEvolutions(databaseApi.database("default"))
}
}
开发者ID:h3poteto,项目名称:ayanerer-scala,代码行数:30,代码来源:DatabaseSpec.scala
示例7: HomeControllerSpec
//设置package包名称以及导入依赖的类
package benchq
import controllers.HomeController
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play._
import play.api._
import play.api.db.evolutions.Evolutions
import play.api.db.{Database, Databases}
import play.api.test.Helpers._
import play.api.test._
class HomeControllerSpec extends PlaySpec with BeforeAndAfterAll {
lazy val components = {
val env = Environment.simple()
val context = ApplicationLoader.createContext(env)
new BenchQComponents(context) {
// prevent connecting to the real db
override lazy val database: Database = Databases.inMemory()
}
}
implicit lazy val app = components.application
override def beforeAll(): Unit = {
Evolutions.applyEvolutions(components.database)
}
override def afterAll(): Unit = {
components.database.shutdown()
}
"HomeController GET" should {
"redirect on index" in {
val controller = components.homeController
val home = controller.index().apply(FakeRequest())
status(home) mustBe SEE_OTHER
redirectLocation(home) mustBe Some(components.config.Http.reverseRoutePrefix + "/tasks")
}
"render the queue" in {
val controller = components.homeController
val home = controller.tasks().apply(FakeRequest())
status(home) mustBe OK
contentType(home) mustBe Some("text/html")
contentAsString(home) must include("Benchmark Tasks")
}
}
}
开发者ID:scala,项目名称:compiler-benchq,代码行数:49,代码来源:HomeControllerSpec.scala
示例8: DbMigrations
//设置package包名称以及导入依赖的类
package util
import play.api.db.evolutions.Evolutions
import play.api.db.{Database, Databases}
import scala.util.Try
object DbMigrations {
private var inMemoryDb: Option[Database] = None
private var deliveredDbs = 0
def getMigratedDb(): Database = {
if(inMemoryDb == None) {
inMemoryDb = Some(Databases.inMemory())
Try {
Evolutions.applyEvolutions(inMemoryDb.get)
}
}
deliveredDbs += 1
inMemoryDb.get
}
def cleanUpDb() = {
deliveredDbs -= 1
if(deliveredDbs == 0 && inMemoryDb != None) {
Evolutions.cleanupEvolutions(inMemoryDb.get)
inMemoryDb = None
}
}
}
开发者ID:ruffythepirate,项目名称:blue-squirrel,代码行数:34,代码来源:DbMigrations.scala
示例9: ApplicationSpec
//设置package包名称以及导入依赖的类
package controllers
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.db.evolutions.Evolutions
import play.api.db.{Database, Databases}
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.Helpers._
import play.api.test._
import util.DbMigrations
class ApplicationSpec extends PlaySpec with OneAppPerSuite with BeforeAndAfterAll {
// This is actually not necessary. Evolutions are done automatic when One App is generated.
var inMemoryDb: Database = _
lazy override val app = new GuiceApplicationBuilder()
.overrides(bind[Database].toInstance(inMemoryDb))
.build()
override def beforeAll() = {
inMemoryDb = DbMigrations.getMigratedDb()
}
override def afterAll() = {
DbMigrations.cleanUpDb()
}
"BlogPostController.index" when {
"blogpost exists" should {
"return ok" in {
val res = route(app, FakeRequest(GET, "/posts/1")).get
assert(status(res) === OK)
}
}
}
"Application" should {
"send 404 on a bad request" in {
val res = route(app, FakeRequest(GET, "/boum")).get
assert(status(res) === NOT_FOUND)
}
"render the index page" in {
val home = route(app, FakeRequest(GET, "/")).get
assert(status(home) === OK)
assert(contentType(home) === Some("text/html"))
}
}
}
开发者ID:ruffythepirate,项目名称:blue-squirrel,代码行数:56,代码来源:ApplicationSpec.scala
注:本文中的play.api.db.evolutions.Evolutions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论