本文整理汇总了Scala中slick.jdbc.JdbcBackend.Database类的典型用法代码示例。如果您正苦于以下问题:Scala Database类的具体用法?Scala Database怎么用?Scala Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: createSchemaWork
//设置package包名称以及导入依赖的类
package io.scalac.wtf.domain
import cats.data.Reader
import slick.jdbc.JdbcBackend.Database
import slick.lifted.TableQuery
import slick.driver.H2Driver.api._
import io.scalac.wtf.domain.tables.Users
trait DatabaseDependancy {
val db = Database.forConfig("h2mem1")
//Used for showcase only, the table should already exist in a realistic scenario
def createSchemaWork = Reader((config: Config) =>
{
implicit val ec = config.ec
for {
_ <- TableQuery[Users].schema.create
} yield ()
}
)
}
示例2: MysqlDBConnection
//设置package包名称以及导入依赖的类
package db
import slick.driver.JdbcProfile
import slick.backend.DatabaseConfig
import slick.jdbc.JdbcBackend.Database
trait DBConnectionComponent {
val dbConnection: DBConnection
class MysqlDBConnection extends DBConnection {
lazy val profile = slick.driver.MySQLDriver
lazy val config:String = "default"
lazy val dc = DatabaseConfig.forConfig[JdbcProfile](config)
}
}
trait DBConnection {
val dc: DatabaseConfig[JdbcProfile]
val profile: slick.driver.JdbcProfile
val db = dc.db
}
示例3: getPostSummaries
//设置package包名称以及导入依赖的类
package docs.home.scaladsl.persistence
import akka.NotUsed
//#imports
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import slick.jdbc.JdbcBackend.Database
//#imports
import docs.home.scaladsl.persistence.SlickRepos.Initial.PostSummaryRepository
trait SlickReadSideQuery {
trait BlogService extends Service {
def getPostSummaries(): ServiceCall[NotUsed, Seq[PostSummary]]
override def descriptor = ???
}
//#service-impl
class BlogServiceImpl(db: Database, val postSummaryRepo: PostSummaryRepository) extends BlogService {
override def getPostSummaries() = ServiceCall { request =>
db.run(postSummaryRepo.selectPostSummaries())
}
//#service-impl
}
}
示例4: Remove
//设置package包名称以及导入依赖的类
package spider.cli
package command
import spider.Util.{ errorExit }
import spider.cli.CLI._
import spider.cli.Args._
import spider.database._
import spider.database.FarmDB.SyncDB
import com.github.nscala_time.time.Imports._
import slick.jdbc.JdbcBackend.Database
object Remove {
case class RemoveArgs(
dates: Args[IndexedSeq[DateTime]] = DatesArg(),
config: Args[DBConfig] = ConfigArg())
def parseArgs(args: Seq[String]): RemoveArgs = {
@annotation.tailrec
def parseArgsImpl(
acc: RemoveArgs, rest: Seq[String]): RemoveArgs = rest match {
case e if rest.isEmpty ? acc
case acc.dates.update(dates, next) ?
parseArgsImpl(acc.copy(dates = dates), next)
case acc.config.update(config, next) ?
parseArgsImpl(acc.copy(config = config), next)
case other +: tail ? errorExit(s"unknown option $other")
}
parseArgsImpl(RemoveArgs(), args)
}
def remove(db: Database, dates: Seq[DateTime]) = {
import scala.concurrent.ExecutionContext.Implicits._
db.runSync(FarmTable.clearRecordsAction(dates))
}
def apply(args: Seq[String]): Unit = {
val a = parseArgs(args)
val dates = a.dates.getOrExit
val db = FarmDB.getConnection(a.config.getOrExit)
remove(db, dates)
}
}
示例5: 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")
}