本文整理汇总了Scala中play.api.db.slick.DatabaseConfigProvider类的典型用法代码示例。如果您正苦于以下问题:Scala DatabaseConfigProvider类的具体用法?Scala DatabaseConfigProvider怎么用?Scala DatabaseConfigProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseConfigProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CertificateStateDAOImpl
//设置package包名称以及导入依赖的类
package daos.util.impl
import javax.inject.Inject
import daos.util.CertificateStateDAO
import models.CertificateState
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class CertificateStateDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends CertificateStateDAO with SlickDAO {
import driver.api._
def findByName(name: String) = {
val query = for {
dbState <- slickCertificateState.filter(_.name === name)
} yield dbState
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case state =>
CertificateState(
id = state.certificateStateID,
name = state.name
)
}
}
}
def find(stateID: Int) = {
val query = for {
dbState <- slickCertificateState.filter(a => a.certificateStateId === stateID)
} yield dbState
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case state =>
CertificateState(
id = state.certificateStateID,
name = state.name
)
}
}
}
def allCertificateStates = db.run(slickCertificateState.map(_.name).result)
}
示例2: MerchantAreasDAOImpl
//设置package包名称以及导入依赖的类
package daos.merchant.impl
import java.util.UUID
import javax.inject.Inject
import models.{ MerchantAreas, ServeArea }
import daos.merchant.MerchantAreasDAO
import daos.util.ServeAreaDAO
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class MerchantAreasDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider, serveAreaDAO: ServeAreaDAO) extends MerchantAreasDAO with SlickDAO {
import driver.api._
def save(userID: UUID, area: ServeArea) = {
val dbMerchAreas = DBMerchantAreas(userID.toString, area.id)
val act = (for {
exist <- slickMerchantAreas += dbMerchAreas
} yield ()).transactionally
db.run(act).map { _ => area }
}
def clear(userID: UUID) = {
val actions = for {
merchants <- slickMerchantAreas.filter(_.merchantId === userID.toString)
} yield merchants
db.run(actions.delete).map(_ => MerchantAreas(Seq()))
}
def deleteOne(userID: UUID, serveArea: ServeArea) = {
val actions = for {
ma <- slickMerchantAreas.filter(ma => ma.merchantId === userID.toString && ma.areaId === serveArea.id)
} yield ma
db.run(actions.delete).map(_ => serveArea)
}
}
示例3: MerchantCertificatesDAOImpl
//设置package包名称以及导入依赖的类
package daos.merchant.impl
import java.util.UUID
import javax.inject.Inject
import daos.merchant.MerchantCertificatesDAO
import models.slick.SlickDAO
import models.{ CertificateState, CertificateType, MerchantCertificate, MerchantCertificates }
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class MerchantCertificatesDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends MerchantCertificatesDAO with SlickDAO {
import driver.api._
def save(userID: UUID, cert: MerchantCertificate) = {
val dbCert = DBCertificates(None, cert.name, cert.description, cert.value, cert.certificate_type.id)
val insertCertificate = slickCertificates.returning(slickCertificates.map(_.id)).
into((cer, id) => cer.copy(certificateID = Some(id))) += dbCert
val act = (for {
certificate <- insertCertificate
_ <- slickMerchantCertificates += DBMerchantCertificates(userID.toString, certificate.certificateID.get)
} yield ()).transactionally
db.run(act).map { _ => cert }
}
def clear(userID: UUID) = {
val mc = slickMerchantCertificates.filter(_.merchantId === userID.toString)
val c = slickCertificates.filter(_.id in mc.map(_.certificateId))
db.run((mc.delete andThen c.delete).transactionally).map(_ => MerchantCertificates(Seq()))
}
def deleteOne(userID: UUID, cert: MerchantCertificate) = {
val actions = for {
ma <- slickMerchantCertificates.filter(ma => ma.merchantId === userID.toString && ma.certificateId === cert.id)
} yield ma
db.run(actions.delete).map(_ => cert)
}
}
示例4: CustomerCertificatesDAOImpl
//设置package包名称以及导入依赖的类
package daos.customer.impl
import java.util.UUID
import javax.inject.Inject
import daos.customer.CustomerCertificatesDAO
import models.slick.SlickDAO
import models.{ CertificateState, _ }
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class CustomerCertificatesDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends CustomerCertificatesDAO with SlickDAO {
import driver.api._
def save(userID: UUID, cert: Certificate) = {
val act = (for {
_ <- slickCustomerCertificates += DBCustomerCertificates(userID.toString, cert.id, cert.code, cert.state.id, cert.bought_at, cert.expires_at)
} yield ()).transactionally
db.run(act).map { _ => cert }
}
def clear(userID: UUID) = {
val cc = slickCustomerCertificates.filter(_.customerId === userID.toString)
db.run(cc.delete.transactionally).map(_ => CustomerCertificates(Seq()))
}
def deleteOne(userID: UUID, certID: Int) = {
val actions = for {
ma <- slickCustomerCertificates.filter(ma => ma.customerId === userID.toString && ma.certificateId === certID)
} yield ma
db.run(actions.delete).map(_ => certID)
}
}
示例5: ServeAreaDAOImpl
//设置package包名称以及导入依赖的类
package daos.util.impl
import javax.inject.Inject
import daos.util.ServeAreaDAO
import models.ServeArea
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class ServeAreaDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends ServeAreaDAO with SlickDAO {
import driver.api._
def findByName(name: String) = {
val query = for {
dbArea <- slickServeAreas.filter(_.name === name)
} yield dbArea
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case area =>
ServeArea(
id = area.areaID,
name = area.name,
description = area.description
)
}
}
}
def find(areaID: Int) = {
val query = for {
dbArea <- slickServeAreas.filter(_.id === areaID)
} yield dbArea
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case area =>
ServeArea(
id = area.areaID,
name = area.name,
description = area.description
)
}
}
}
def allServeAreas = db.run(slickServeAreas.map(_.name).result)
}
示例6: CityDAOImpl
//设置package包名称以及导入依赖的类
package daos.util.impl
import javax.inject.Inject
import daos.util.CityDAO
import models.City
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class CityDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends CityDAO with SlickDAO {
import driver.api._
def findByName(name: String) = {
val query = for {
dbCity <- slickCity.filter(_.name === name)
} yield dbCity
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case city =>
City(
city.cityID,
city.name)
}
}
}
def find(cityID: Int) = {
val query = for {
dbCity <- slickCity.filter(_.id === cityID)
} yield dbCity
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case city =>
City(
city.cityID,
city.name)
}
}
}
def allCityNames = {
val query = slickCity.map(_.name)
db.run(query.result)
}
}
示例7: CertificateTypeDAOImpl
//设置package包名称以及导入依赖的类
package daos.util.impl
import javax.inject.Inject
import daos.util.CertificateTypeDAO
import models.CertificateType
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
class CertificateTypeDAOImpl @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends CertificateTypeDAO with SlickDAO {
import driver.api._
def findByName(name: String) = {
val query = for {
dbType <- slickCertificateType.filter(_.name === name)
} yield dbType
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case certType =>
CertificateType(
id = certType.certificateTypeID,
name = certType.name
)
}
}
}
def find(typeID: Int) = {
val query = for {
dbType <- slickCertificateType.filter(_.certificateId === typeID)
} yield dbType
db.run(query.result.headOption).map { resultOption =>
resultOption.map {
case certType =>
CertificateType(
id = certType.certificateTypeID,
name = certType.name
)
}
}
}
def allCertificateTypes = db.run(slickCertificateType.map(_.name).result)
}
示例8: PetRecord
//设置package包名称以及导入依赖的类
package services.database
import com.google.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import slick.driver.JdbcProfile
case class PetRecord(id: Int, name: String, notes: String)
object PetRecord {
implicit val petRecordFormat = Json.format[PetRecord]
}
class PetsRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val db = dbConfig.db
import dbConfig.driver.api._
val pets = TableQuery[PetsTable]
class PetsTable(tag: Tag) extends Table[PetRecord](tag, "PETS") {
def id = column[Int]("ID", O.AutoInc, O.PrimaryKey)
def name = column[String]("NAME")
def notes = column[String]("NOTES")
def * = (id, name, notes) <> ((PetRecord.apply _).tupled, PetRecord.unapply)
}
}
示例9: AccountDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import java.sql.Date
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.Account
import scala.concurrent.Future
class AccountDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class AccountTable(tag: Tag) extends Table[Account] (tag, "Account"){
def account_id = column[Long]("account_id", O.PrimaryKey, O.AutoInc)
def user_id = column[Option[Long]]("user_id")
def name = column[String]("name")
def amount = column[Long]("amount")
def category_id = column[Long]("category_id")
def register_at = column[Date]("register_at")
def payment_source_id = column[Option[Long]]("payment_source_id")
def payment_destination_id = column[Option[Long]]("payment_destination_id")
override def * = (
account_id,
user_id,
name,
amount,
category_id,
register_at,
payment_source_id,
payment_destination_id) <> (Account.tupled, Account.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val accounts = TableQuery[AccountTable]
def list: Future[Seq[Account]] = {
dbConfig.db.run(accounts.result)
}
}
示例10: PaymentDestinationDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.PaymentDestination
import scala.concurrent.Future
class PaymentDestinationDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class PaymentDestinationTable(tag: Tag) extends Table[PaymentDestination] (tag, "PaymentDestination"){
def payment_destination_id = column[Long]("payment_destination_id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def user_id = column[Option[Long]]("user_id")
override def * = (
payment_destination_id,
name,
user_id) <> (PaymentDestination.tupled, PaymentDestination.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val paymentDestination = TableQuery[PaymentDestinationTable]
def list: Future[Seq[PaymentDestination]] = {
dbConfig.db.run(paymentDestination.result)
}
}
示例11: CategoryDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.Category
import scala.concurrent.Future
class CategoryDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class CategoryTable(tag: Tag) extends Table[Category] (tag, "Category"){
def category_id = column[Long]("category_id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def hierarchy = column[Long]("hierarchy")
def user_id = column[Option[Long]]("user_id")
def parent_id = column[Option[Long]]("parent_id")
override def * = (
category_id,
name,
hierarchy,
user_id,
parent_id) <> (Category.tupled, Category.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val category = TableQuery[CategoryTable]
def list: Future[Seq[Category]] = {
dbConfig.db.run(category.result)
}
}
示例12: LanguageTable
//设置package包名称以及导入依赖的类
package repository
import com.google.inject.Inject
import com.google.inject.ImplementedBy
import models.Language
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.Future
trait LanguageTable extends UserTable{ self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class LanguageTable(tag:Tag) extends Table[Language](tag,"language") {
val id=column[Int]("id")
val name= column[String]("name", O.SqlType("VARCHAR(200)"))
val fluency=column[String]("fluency", O.SqlType("VARCHAR(200)"))
def * = (id, name,fluency) <>(Language.tupled, Language.unapply)
}
val languageTableQuery = TableQuery[LanguageTable]
}
//@ImplementedBy(classOf[LanguageImpl])
class LanguageRepo @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends LanguageTable with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
def insert(id: Int, name: String, fluency: String): Future[Int] = {
val insertQuery=languageTableQuery += Language(id, name, fluency)
db.run {insertQuery}
}
def update(id: Int, name: String, fluency: String): Future[Int] = db.run {languageTableQuery.filter(_.id === id).update(Language(id, name, fluency))}
def delete(name:String): Future[Int] = db.run { languageTableQuery.filter(_.name === name).delete}
def getAll(): Future[List[Language]] = db.run {
val test=languageTableQuery.to[List]
test.result
}
def getLanguage(id:Int): Future[Seq[Language]] = {
db.run(languageTableQuery.filter(_.id === id).result)
}
}
示例13: Campaign
//设置package包名称以及导入依赖的类
package models
import play.api.Play
import slick.driver.H2Driver.api._
import scala.concurrent.Future
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import slick.driver.JdbcProfile
case class Campaign(id: Option[Int], title: String, content: String)
trait CampaignsTable {
class Campaigns(tag: Tag) extends Table[Campaign](tag, "CAMPAIGNS") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def title = column[String]("TITLE")
def content = column[String]("CONTENT")
def * = (id.?, title, content) <> (Campaign.tupled, Campaign.unapply)
}
val campaigns = TableQuery[Campaigns]
}
object CampaignsDAO extends HasDatabaseConfig[JdbcProfile] with CampaignsTable {
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
def findById(id: Int): Future[Option[Campaign]] =
db.run(campaigns.filter(_.id === id).result.headOption)
def findAll: Future[Seq[Campaign]] =
db.run(campaigns.result)
def insert(newRecord: Campaign): Future[Int] = {
db.run((campaigns returning campaigns.map(_.id)) += newRecord)
}
def update(record: Campaign): Future[Int] = {
db.run(campaigns.filter(_.id === record.id)
.map(a => (a.title, a.content))
.update((record.title, record.content)))
}
def getCampaignIds: Future[Seq[Int]] = {
db.run(campaigns.map(row => (row.id)).result)
}
}
示例14: PersonDAOImpl
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import javax.inject.Singleton
import scala.concurrent.Future
import play.api.Configuration
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.db.NamedDatabase
import models.Person
import slick.driver.JdbcProfile
@Singleton
class PersonDAOImpl @Inject() (@NamedDatabase("mydb") protected val dbConfigProvider: DatabaseConfigProvider, conf: Configuration) extends PersonDAO with HasDatabaseConfigProvider[JdbcProfile] with Tables {
import driver.api._
val loadedDb = conf.getString("slick.dbs.mydb.db.url")//just for demo, should be "blah" in PersonDAOImplSpec
println("LOADED CONFIG FOR DB: " + loadedDb)
def findAll(): Future[Seq[Person]] =
db.run(persons.result).map { res => println("Hello from real DAO!"); res }
def insert(p: Person): Future[Int] =
db.run(persons += p)
def createTables(): Future[Unit] =
db.run(persons.schema.create)
}
trait Tables { self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class PersonsTable(tag: Tag) extends Table[Person](tag, "PERSON") {
def id = column[Int]("ID", O.PrimaryKey)
def name = column[String]("NAME")
def age = column[Int]("AGE")
def * = (id, name, age) <> (Person.tupled, Person.unapply _)
}
lazy val persons = TableQuery[PersonsTable]
}
示例15: PayeeDao
//设置package包名称以及导入依赖的类
package dao
import javax.inject._
import models.KakeiboDataDtos.PayeeDto
import models.KakeiboDataModels.Payee
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile
import scala.concurrent.Future
@Singleton
class PayeeDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider,
val payMethodDao: PayMethodDao
)
extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
private val payeeQuery = TableQuery[PayeeTable]
def all(): Future[Seq[PayeeDto]] = {
db.run(payeeQuery.result)
}
def insert(item: PayeeDto) = {
db.run(payeeQuery += item)
}
def insert(items: Seq[PayeeDto]) = {
db.run(payeeQuery ++= items)
}
def findById(id: Long): Future[PayeeDto] = {
db.run(payeeQuery.filter(_.id === id).result.head)
}
def payee(id: Long): Future[Payee] = {
db.run(payeeQuery.filter(_.id === id).result.head).flatMap(dto => {
val payMethod = payMethodDao.payMethod(dto.payMethodId)
payMethod.map(v => Payee(dto.id, dto.name, v))
})
}
class PayeeTable(tag: Tag) extends Table[PayeeDto](tag, "PayeeDto") {
def id = column[Long]("Id", O.PrimaryKey)
def name = column[String]("Name")
def payMethodId = column[Long]("PayMethod")
override def * = (id, name, payMethodId) <>(PayeeDto.tupled, PayeeDto.unapply _)
def payMethod = foreignKey("PayMethod_FK", payMethodId, TableQuery[payMethodDao.PayMethodTable])(_.id)
}
}