本文整理汇总了Scala中slick.jdbc.JdbcBackend类的典型用法代码示例。如果您正苦于以下问题:Scala JdbcBackend类的具体用法?Scala JdbcBackend怎么用?Scala JdbcBackend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JdbcBackend类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: SyncableFuture
//设置package包名称以及导入依赖的类
package moe.pizza
import slick.driver.MySQLDriver
import slick.jdbc.JdbcBackend
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.language.postfixOps
implicit class SyncableFuture[T](f: Future[T]) {
def sync(duration: Duration = 10 seconds): T = {
Await.result(f, duration)
}
}
implicit class RunnableMysqlStreamingAction[+R, +T, -E <: slick.dbio.Effect](m: MySQLDriver.StreamingDriverAction[R, T, E]) {
def run(d: JdbcBackend.DatabaseDef) = {
d.run(m)
}
}
}
开发者ID:greg2010,项目名称:pizza-eveapi-mirror,代码行数:23,代码来源:package.scala
示例2: StaticPagesDAO
//设置package包名称以及导入依赖的类
package com.grimey.staticpage
import java.time.LocalDateTime
import slick.jdbc.JdbcBackend
import slick.driver.MySQLDriver.api._
import slick.lifted.TableQuery
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
private[staticpage] object StaticPagesDAO extends TableQuery(new StaticPagesTable(_)) {
def edit(htmlContent: String, pageType: String, db: JdbcBackend#DatabaseDef): Future[StaticPage] = {
// Todo: Don't forget to update the updated field.
???
}
def getAllStaticPages(db: JdbcBackend#DatabaseDef): Future[Seq[StaticPage]] = db.run(this.to[Seq].result)
def find(pageType: String, db: JdbcBackend#DatabaseDef): Future[Option[StaticPage]] = {
db.run(this.filter(_.pageType === pageType).result).map(_.headOption)
}
def create(htmlContent: String, pageType: String, db: JdbcBackend#DatabaseDef,
created: LocalDateTime = LocalDateTime.now(), updated: LocalDateTime = LocalDateTime.now()): Future[StaticPage] = {
db.run(this returning this.map(_.id)
into ((staticPage, id) => staticPage.copy(id - id)) += StaticPage(0, htmlContent, pageType, created, updated))
}
def delete(pageType: String, db: JdbcBackend#DatabaseDef): Future[Int] = {
db.run(this.filter(_.pageType === pageType).delete)
}
}
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:34,代码来源:StaticPagesDAO.scala
示例3: TestAppComponents
//设置package包名称以及导入依赖的类
package com.grimey.utils
import java.io.File
import com.grimey.{DatabaseContextConfig, GrimeyDatabaseContext, GrimeyAppComponents}
import play.api
import play.api.{Mode, Environment, ApplicationLoader}
import play.api.ApplicationLoader.Context
import scala.concurrent.duration._
import slick.jdbc.JdbcBackend
trait TestUtils {
// Todo: This should be injected.
protected lazy val db: JdbcBackend#DatabaseDef =
new GrimeyDatabaseContext(DatabaseContextConfig(defaultTimeout = 10.seconds)).db
implicit lazy val app: api.Application = {
val appLoader = new TestAppLoader()
val context = ApplicationLoader.createContext(
new Environment(new File("."), ApplicationLoader.getClass.getClassLoader, Mode.Test)
)
appLoader.load(context)
}
}
class TestAppComponents(context: Context) extends GrimeyAppComponents(context) {
// Todo: Add test specific configuration here when applicable.
}
class TestAppLoader extends ApplicationLoader {
override def load(context: Context): api.Application = new TestAppComponents(context).application
}
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:34,代码来源:TestUtils.scala
示例4: slickpostgresql
//设置package包名称以及导入依赖的类
//import com.typesafe.config.Config
import slick.driver.PostgresDriver.api._
import scala.concurrent.ExecutionContext.Implicits.global
import slick.jdbc.JdbcBackend
import slick.jdbc.JdbcBackend.Database
//import slick.driver.MySQLDriver.api._
import java.text.SimpleDateFormat
import java.util.Calendar
object slickpostgresql {
def main(args: Array[String]) {
val db = Database.forConfig("database")
try {
// ...
} finally db.close
println("Hi, there!")
}
}
开发者ID:bar2cha,项目名称:slick-postgresql,代码行数:24,代码来源:slick-postgresql.scala
示例5: config
//设置package包名称以及导入依赖的类
package akka.persistence.pg.util
import java.sql.Savepoint
import java.util.concurrent.TimeUnit
import akka.actor.ActorSystem
import akka.persistence.pg.PluginConfig
import akka.testkit.TestProbe
import akka.util.Timeout
import com.typesafe.config.Config
import org.scalatest._
import slick.jdbc.JdbcBackend
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.util.Try
trait PersistentActorTest extends fixture.FunSuiteLike
with BeforeAndAfterEach {
def config: Config
implicit val defaultTimeout = Timeout(10, TimeUnit.SECONDS)
implicit var system: ActorSystem = _
var testProbe: TestProbe = _
override protected def beforeEach(): Unit = {
system = ActorSystem("PersistentActorTest", config)
testProbe = TestProbe()
}
type FixtureParam = JdbcBackend.DatabaseDef
override protected def withFixture(test: OneArgTest): Outcome = {
val possibleOutcome = Try {
PgPluginTestUtil.withTransactionRollback { db =>
withFixture(test.toNoArgTest(db))
}
}
//akka shutdown must be done in this way instead of using afterEach
system.terminate()
Await.result(system.whenTerminated, Duration.Inf)
possibleOutcome.get
}
def savepoint()(implicit db: JdbcBackend.DatabaseDef): Savepoint = db.createSession().conn.setSavepoint()
def rollback(savepoint: Savepoint)(implicit db: JdbcBackend.DatabaseDef) = db.createSession().conn.rollback(savepoint)
}
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:53,代码来源:PersistentActorTest.scala
示例6: DatabaseInitializer
//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.ui.db
import java.io.PrintWriter
import java.sql.Connection
import java.util.logging.Logger
import javax.sql.DataSource
import org.flywaydb.core.Flyway
import slick.jdbc.JdbcBackend
class DatabaseInitializer(db: JdbcBackend.Database) {
def initDatabase(): JdbcBackend.Database = {
migrateIfNeeded(db)
db
}
private def migrateIfNeeded(db: JdbcBackend.Database) = {
val flyway = new Flyway()
flyway.setDataSource(new DatabaseDataSource(db))
flyway.setBaselineOnMigrate(true)
flyway.migrate()
}
}
class DatabaseDataSource(db: JdbcBackend.Database) extends DataSource {
private val conn = db.createSession().conn
override def getConnection: Connection = conn
override def getConnection(username: String, password: String): Connection = conn
override def unwrap[T](iface: Class[T]): T = conn.unwrap(iface)
override def isWrapperFor(iface: Class[_]): Boolean = conn.isWrapperFor(iface)
override def setLogWriter(out: PrintWriter): Unit = ???
override def getLoginTimeout: Int = ???
override def setLoginTimeout(seconds: Int): Unit = ???
override def getParentLogger: Logger = ???
override def getLogWriter: PrintWriter = ???
}
开发者ID:TouK,项目名称:nussknacker,代码行数:39,代码来源:DatabaseInitializer.scala
示例7: SampleDataInserter
//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.ui.db.migration
import db.migration.DefaultJdbcProfile
import pl.touk.nussknacker.ui.db.EspTables
import slick.jdbc.JdbcBackend
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.util.Try
object SampleDataInserter {
import DefaultJdbcProfile.profile.api._
implicit val ec = scala.concurrent.ExecutionContext.global
def insert(db: JdbcBackend.DatabaseDef) = {
// There is some slick issue with uppsert https://github.com/slick/slick/issues/966
// So we do some quick and dirty uppserts, but it's ok because it's development data
TryWithAwait(db.run(EspTables.environmentsTable += SampleData.environment))
TryWithAwait(db.run(EspTables.processesTable += SampleData.process))
TryWithAwait(db.run(EspTables.processVersionsTable += SampleData.processVersion))
TryWithAwait(db.run(EspTables.deployedProcessesTable += SampleData.deployedProcess))
TryWithAwait(db.run(EspTables.tagsTable ++= SampleData.tags))
upsertComments(db)
}
def upsertComments(db: JdbcBackend.DatabaseDef): Try[Option[Int]] = {
TryWithAwait(db.run(EspTables.commentsTable.filter(_.user === "TouK").delete))
TryWithAwait(db.run(EspTables.commentsTable ++= SampleData.comments))
}
def TryWithAwait[A](a: Future[A]) = {
Try { Await.result(a, 1 minute) }
}
}
开发者ID:TouK,项目名称:nussknacker,代码行数:35,代码来源:SampleDataInserter.scala
示例8: DeployedProcessRepository
//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.ui.process.repository
import java.sql.Timestamp
import java.time.LocalDateTime
import pl.touk.nussknacker.ui.app.BuildInfo
import pl.touk.nussknacker.ui.db.EspTables
import pl.touk.nussknacker.ui.db.EspTables._
import pl.touk.nussknacker.ui.db.entity.ProcessDeploymentInfoEntity.{DeployedProcessVersionEntityData, DeploymentAction}
import pl.touk.nussknacker.ui.db.entity.ProcessVersionEntity.ProcessVersionEntityData
import slick.jdbc.{JdbcBackend, JdbcProfile}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.language.higherKinds
class DeployedProcessRepository(db: JdbcBackend.Database,
driver: JdbcProfile,
buildInfo: Map[String, String]) {
import driver.api._
def markProcessAsDeployed(processVersion: ProcessVersionEntityData, userId: String, environment: String)
(implicit ec: ExecutionContext): Future[Unit] = {
val insertAction = EspTables.deployedProcessesTable += DeployedProcessVersionEntityData(
processVersion.processId,
Some(processVersion.id),
environment,
userId,
Timestamp.valueOf(LocalDateTime.now()),
DeploymentAction.Deploy,
Some(BuildInfo.writeAsJson(buildInfo))
)
db.run(insertAction).map(_ => ())
}
def markProcessAsCancelled(processId: String, userId: String, environment: String)
(implicit ec: ExecutionContext): Future[Unit] = {
val insertAction = EspTables.deployedProcessesTable += DeployedProcessVersionEntityData(
processId,
None,
environment,
userId,
Timestamp.valueOf(LocalDateTime.now()),
DeploymentAction.Cancel,
None
)
db.run(insertAction).map(_ => ())
}
}
开发者ID:TouK,项目名称:nussknacker,代码行数:51,代码来源:DeployedProcessRepository.scala
示例9: DbTesting
//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.ui.api.helpers
import com.typesafe.scalalogging.LazyLogging
import pl.touk.nussknacker.ui.db.DatabaseInitializer
import slick.jdbc.JdbcBackend
import scala.util.Try
object DbTesting extends LazyLogging {
val db: JdbcBackend.Database = JdbcBackend.Database.forURL(
url = s"jdbc:hsqldb:mem:esp;sql.syntax_ora=true",
driver = "org.hsqldb.jdbc.JDBCDriver",
user = "SA",
password = ""
)
new DatabaseInitializer(db).initDatabase()
def cleanDB(): Try[Unit] = {
Try {
val session = db.createSession()
session.prepareStatement("""delete from "process_attachments"""").execute()
session.prepareStatement("""delete from "process_comments"""").execute()
session.prepareStatement("""delete from "process_deployment_info"""").execute()
session.prepareStatement("""delete from "process_versions"""").execute()
session.prepareStatement("""delete from "tags"""").execute()
session.prepareStatement("""delete from "environments"""").execute()
session.prepareStatement("""delete from "processes"""").execute()
}
}
}
开发者ID:TouK,项目名称:nussknacker,代码行数:32,代码来源:DbTesting.scala
示例10: Postgres
//设置package包名称以及导入依赖的类
package com.snapswap.db
import javax.sql.DataSource
import com.opentable.db.postgres.embedded.PreparedDbProvider
import com.typesafe.config.{Config, ConfigFactory}
import slick.jdbc.JdbcBackend
import scala.collection.JavaConversions._
trait Postgres {
val conf: Config = ConfigFactory.load()
private val preparer = {
val paths: Seq[(String, Option[String])] = conf.getStringList("flyway-preparer").map { value =>
val pair: Array[String] = value.split(':')
if (pair.length == 1) {
(pair(0), None)
} else {
(pair(0), Option(pair.apply(1)))
}
}
FlywayPreparer(paths: _*)
}
protected val provider: PreparedDbProvider = PreparedDbProvider.forPreparer(preparer)
protected lazy val dataSource: DataSource = provider.createDataSource
}
object Postgres extends Postgres with JdbcBackend {
def nextDB: Database =
Database.forDataSource(provider.createDataSource, None)
trait Fixture {
val db: Database = Database.forDataSource(provider.createDataSource, None)
}
}
开发者ID:snap-swap,项目名称:slick-postgres-testkit,代码行数:42,代码来源:Postgres.scala
示例11: dbSession
//设置package包名称以及导入依赖的类
package org.dohrm.toolkit.actor
import akka.actor.Actor
import org.dohrm.toolkit.actor.response.Response
import org.dohrm.toolkit.context.JdbcContext
import slick.jdbc.JdbcBackend
import scala.concurrent.{ExecutionContext, Future}
trait JdbcActor
extends Actor with JdbcContext {
import jdbcConfig._
import driver.api._
implicit def dbSession: JdbcBackend.SessionDef = jdbcConfig.db.createSession()
def exec[A, B](action: DBIOAction[A, NoStream, Nothing])(mapper: A => Response[B])(implicit ec: ExecutionContext): Future[Response[B]] = {
db.run(action)
.map(mapper)
}
def forwardToSender[A](f: Future[Response[A]])(implicit ec: ExecutionContext): Unit = {
val previousSender = sender
f.recover(
(exceptionToErrorMapper orElse defaultExceptionToErrorMapper) andThen { e => Response.failed(e) }
).foreach { r =>
previousSender ! r
}
}
def execAndForwardToSender[A, B](action: DBIOAction[A, NoStream, Nothing])(mapper: A => Response[B])(implicit ec: ExecutionContext): Unit = {
forwardToSender(
exec(action)(mapper)
)
}
}
开发者ID:dohr-michael,项目名称:storyline,代码行数:40,代码来源:JdbcActor.scala
示例12: db
//设置package包名称以及导入依赖的类
package org.dohrm.toolkit.utils
import com.github.tototoshi.slick.{PostgresJodaSupport, GenericJodaSupport}
import org.dohrm.toolkit.actor.response.{InvalidRequestError, ExceptionError, Error}
import org.dohrm.toolkit.context.{ConfigContext, JdbcConfig, JdbcContext}
import org.postgresql.util.PSQLException
import slick.driver.JdbcProfile
import slick.jdbc.JdbcBackend
trait PostgresSupport extends JdbcContext {
self: ConfigContext =>
private val DbConfig = config.getConfig("postgres")
private lazy val lazyDb = JdbcBackend.Database.forURL(
url = s"jdbc:postgresql://${DbConfig.getString("url")}:${DbConfig.getString("port")}/${DbConfig.getString("database")}",
user = DbConfig.getString("user"),
password = DbConfig.getString("password"),
driver = DbConfig.getString("driver"),
keepAliveConnection = DbConfig.getBoolean("keepAliveConnection")
)
override implicit lazy val jdbcConfig: JdbcConfig = new JdbcConfig {
override val jodaSupport: GenericJodaSupport = PostgresJodaSupport
override def db: JdbcBackend.DatabaseDef = lazyDb
override val driver: JdbcProfile = slick.driver.PostgresDriver
override def exceptionToErrorMapper: PartialFunction[Throwable, Error] = {
case e: PSQLException if e.getServerErrorMessage.getSQLState == "23505"=>
InvalidRequestError(Seq(s"${e.getServerErrorMessage.getTable.toLowerCase}.unique_violation"))
case e: PSQLException =>
println(e.getServerErrorMessage)
ExceptionError(e)
}
}
}
开发者ID:dohr-michael,项目名称:storyline,代码行数:42,代码来源:PostgresSupport.scala
示例13: TestUtils
//设置package包名称以及导入依赖的类
package repos.testutils
import repos.RepoPublisher
import repos.jdbc.JdbcDb
import slick.jdbc.JdbcBackend
import slick.jdbc.JdbcBackend.Database
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
object TestUtils {
def makeH2DB(): JdbcBackend.DatabaseDef = {
Database.forURL(
s"jdbc:h2:mem:test_${util.Random.nextInt};DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1",
driver = "org.h2.Driver")
}
def makeH2JdbcDb(jdb: JdbcBackend.DatabaseDef): JdbcDb = {
new JdbcDb(slick.driver.H2Driver, jdb)
}
def await[R](f: => Future[R]): R = Await.result(f, Duration.Inf)
def awaitStream[T](publisher: RepoPublisher[T]): ArrayBuffer[T] = {
val b = ArrayBuffer.empty[T]
await(publisher.foreach(s => synchronized { b+=s }))
b.result()
}
}
开发者ID:trueaccord,项目名称:repos,代码行数:32,代码来源:TestUtils.scala
示例14: MixInDB
//设置package包名称以及导入依赖的类
package net.petitviolet.infra
import slick.jdbc.JdbcBackend
import slick.jdbc.JdbcBackend.Database
trait UsesDB {
val db: JdbcBackend.DatabaseDef
}
trait MixInDB {
val db: JdbcBackend.DatabaseDef = MixInDB.db
}
// ????????????????????
private object MixInDB {
val db: JdbcBackend.DatabaseDef = Database.forConfig("mysql-local")
}
开发者ID:petitviolet,项目名称:akka-http-slick-ddd,代码行数:18,代码来源:DB.scala
示例15: ThoughtServiceServer
//设置package包名称以及导入依赖的类
package jarta.thoughtservice
import com.twitter.finatra.thrift.ThriftServer
import com.twitter.finatra.thrift.filters._
import com.twitter.finatra.thrift.routing.ThriftRouter
import jarta.thoughtservice.model.ThoughtRepository
import slick.jdbc.JdbcBackend
object ThoughtServiceServer extends ThriftServer {
override val name = "thought-service-server"
override val disableAdminHttpServer = true
override val defaultFinatraThriftPort = ":9997"
override val defaultHttpPort = 9992
private val ThoughtRepository = new ThoughtRepository(JdbcBackend.Database.forConfig("db"))
override def configureThrift(router: ThriftRouter) {
router
.filter[LoggingMDCFilter]
.filter[TraceIdMDCFilter]
.filter[ThriftMDCFilter]
.filter[AccessLoggingFilter]
.filter[StatsFilter]
.add(new ThoughtService(ThoughtRepository))
}
}
开发者ID:lbunschoten,项目名称:jarta,代码行数:28,代码来源:ThoughtServiceServer.scala
注:本文中的slick.jdbc.JdbcBackend类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论