• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala DatabaseConfigProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中play.api.db.slick.DatabaseConfigProvider的典型用法代码示例。如果您正苦于以下问题:Scala DatabaseConfigProvider类的具体用法?Scala DatabaseConfigProvider怎么用?Scala DatabaseConfigProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DatabaseConfigProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)

} 
开发者ID:Bakuchi,项目名称:certification,代码行数:48,代码来源:CertificateStateDAOImpl.scala


示例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)
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:41,代码来源:MerchantAreasDAOImpl.scala


示例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)
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:41,代码来源:MerchantCertificatesDAOImpl.scala


示例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)
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:36,代码来源:CustomerCertificatesDAOImpl.scala


示例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)

} 
开发者ID:Bakuchi,项目名称:certification,代码行数:50,代码来源:ServeAreaDAOImpl.scala


示例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)
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:48,代码来源:CityDAOImpl.scala


示例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)

} 
开发者ID:Bakuchi,项目名称:certification,代码行数:48,代码来源:CertificateTypeDAOImpl.scala


示例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)
  }
} 
开发者ID:microservicesinaction,项目名称:playProject,代码行数:28,代码来源:Pets.scala


示例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)
  }
} 
开发者ID:kogai,项目名称:kakei-log,代码行数:42,代码来源:AccountDAO.scala


示例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)
  }
} 
开发者ID:kogai,项目名称:kakei-log,代码行数:31,代码来源:PaymentDestinationDAO.scala


示例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)
  }
} 
开发者ID:kogai,项目名称:kakei-log,代码行数:35,代码来源:CategoryDAO.scala


示例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)
  }
} 
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:48,代码来源:LanguageRepo.scala


示例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)
  }


} 
开发者ID:kaznishi,项目名称:zz-sandbox-petit-ad,代码行数:48,代码来源:Campaign.scala


示例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]
} 
开发者ID:sake92,项目名称:PlayGuiceExample,代码行数:43,代码来源:PersonDAOImpl.scala


示例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)
  }
} 
开发者ID:dikky1218,项目名称:kakeiboApi,代码行数:57,代码来源:PayeeDao.scala


示例16: ItemDateDao

//设置package包名称以及导入依赖的类
package dao

import javax.inject.{Inject, Singleton}

import models.KakeiboDataDtos.ItemDateDto
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import models.KakeiboDataModels.ItemDate
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile

import scala.concurrent.Future




@Singleton
class ItemDateDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider,
                            val yearMonthDao: YearMonthDao
                           )
  extends HasDatabaseConfigProvider[JdbcProfile]{
  import driver.api._

  private val itemDateQuery = TableQuery[ItemDateTable]

  def all(): Future[Seq[ItemDateDto]] = {
    db.run(itemDateQuery.result)
  }

  def insert(item: ItemDateDto) = {
    db.run(itemDateQuery += item)
  }

  def insert(items: Seq[ItemDateDto]) = {
    db.run(itemDateQuery ++= items)
  }

  def findById(id: Long): Future[ItemDateDto] = {
    db.run(itemDateQuery.filter(_.id === id).result.head)
  }

  def itemDate(id: Long): Future[ItemDate] = {
    db.run(itemDateQuery.filter(_.id === id).result.head).flatMap(dto => {
      val yearMonth = yearMonthDao.yearMonth(dto.yearMonthId)
      yearMonth.map(v => ItemDate(dto.id, dto.date, dto.createdAt, dto.updatedAt, v))
    })
  }

  class ItemDateTable(tag: Tag) extends Table[ItemDateDto](tag, "ItemDateDto"){
    def id = column[Long]("Id", O.PrimaryKey)
    def date = column[String]("Date")
    def createdAt = column[Long]("CreatedAt")
    def updatedAt = column[Long]("UpdatedAt")
    def yearMonthId = column[Long]("YearMonth")

    override def * = (id, date, createdAt, updatedAt, yearMonthId) <> (ItemDateDto.tupled, ItemDateDto.unapply _)

    def yearMonth = foreignKey("YearMonth_FK", yearMonthId, TableQuery[yearMonthDao.YearMonthTable])(_.id)

  }
} 
开发者ID:dikky1218,项目名称:kakeiboApi,代码行数:61,代码来源:ItemDateDao.scala


示例17: Scores

//设置package包名称以及导入依赖的类
package dao

import javax.inject.{Inject, Singleton}

import models._
import play.api.db.slick.{HasDatabaseConfigProvider, DatabaseConfigProvider}
import slick.driver.JdbcProfile

import scala.concurrent.Future


trait ScoreComponent{ self: HasDatabaseConfigProvider[JdbcProfile] =>
  import driver.api._
  class Scores(tag: Tag) extends Table[Score](tag, "Score"){
    def scoreId = column[Option[Int]]("ScoreId", O.PrimaryKey, O.AutoInc)
    def value = column[Double]("Value")
    def assessmentMethodId = column[Int]("AssessmentMethodId")
    def courseId = column[String]("CourseId")
    def academicSeasonId = column[Int]("AcademicSeasonId")

    def * = (scoreId, value, assessmentMethodId, courseId, academicSeasonId) <>((Score.apply _).tupled, Score.unapply _)
  }
}
@Singleton
class ScoreDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
  extends HasDatabaseConfigProvider[JdbcProfile] with ScoreComponent {
  import driver.api._
  private lazy val scores = TableQuery[Scores]

  def countScore(courseId: String, academicId: Int): Future[Int] =
    db.run(scores.filter(s => s.courseId === courseId && s.academicSeasonId === academicId).length.result)

  def insert(listScore: Seq[Score]): Future[Option[Int]] = {
    db.run(scores ++= listScore)
  }
} 
开发者ID:chinhnk00494,项目名称:cw-CMR,代码行数:37,代码来源:ScoreDAO.scala


示例18: GradeStatisticDAO

//设置package包名称以及导入依赖的类
package dao

import javax.inject.{Inject, Singleton}

import models.GradeStatistic
import play.api.db.slick.{HasDatabaseConfigProvider, DatabaseConfigProvider}
import slick.driver.JdbcProfile

import scala.concurrent.Future


@Singleton
class GradeStatisticDAO @Inject()(protected val dbConfigProvider:DatabaseConfigProvider)
  extends HasDatabaseConfigProvider[JdbcProfile] {
  import driver.api._

  class GradeStatistics(tag: Tag) extends Table[GradeStatistic](tag,"GradeStatistic"){
    def cmrId = column[Int]("CMRId",O.PrimaryKey,O.AutoInc)
    def statisticType = column[String]("StatisticType",O.PrimaryKey)
    def assessmentMethodId = column[Int]("AssessmentMethodId",O.PrimaryKey)
    def value = column[Option[Float]]("Value")

    def * = (cmrId,statisticType,assessmentMethodId,value) <> ((GradeStatistic.apply _).tupled, GradeStatistic.unapply _)
  }
  private lazy val gradeStatistics = TableQuery[GradeStatistics]

  def findByCMRId(cmrId: Int): Future[Seq[GradeStatistic]] =
    db.run(gradeStatistics.filter(_.cmrId === cmrId).result)
} 
开发者ID:chinhnk00494,项目名称:cw-CMR,代码行数:30,代码来源:GradeStatisticDAO.scala


示例19: RoleDAO

//设置package包名称以及导入依赖的类
package dao

import javax.inject.{Singleton, Inject}

import models.{User, Role, Permission, RolePermission}
import play.api.db.slick.{HasDatabaseConfigProvider, DatabaseConfigProvider}
import slick.driver.JdbcProfile
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import scala.concurrent.Future


@Singleton
class RoleDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
  extends HasDatabaseConfigProvider[JdbcProfile] with PermissionComponent{

  import driver.api._

  class Roles(tag: Tag) extends Table[Role](tag, "Role") {
    def roleId = column[String]("RoleId", O.PrimaryKey)
    def name = column[String]("Name")
    def description = column[String]("Description")
    def isActive = column[Char]("isActive")
    def * = (roleId, name, description, isActive) <>((Role.apply _).tupled, Role.unapply _)
  }

  class RolesPermissions(tag: Tag) extends Table[RolePermission](tag, "Role_Permission") {
    def roleId = column[String]("RoleId")
    def permissionId = column[Int]("PermissionId")
    def * = (roleId, permissionId) <>((RolePermission.apply _).tupled, RolePermission.unapply _)
  }

  private lazy val roles = TableQuery[Roles]
  private lazy val permissions = TableQuery[Permissions]
  private lazy val rolesPermissions = TableQuery[RolesPermissions]

  def list: Future[Seq[Role]] = db.run(roles.result)

  def findById(id: String): Future[Option[Role]] =
    db.run(roles.filter(_.roleId === id).filter(_.isActive === '1').result.headOption)

  def authority(path: String)(user: User): Future[Boolean] = {
    val query = for {
      (permission, rolePermission) <- permissions.join(rolesPermissions.filter(_.roleId === user.roleId)).on(_.permissionId === _.permissionId)
    } yield (permission)
    val listPermission = db.run(query.result)
    listPermission.map { p =>
      p.exists(v => v.path == path)
    }
  }
} 
开发者ID:chinhnk00494,项目名称:cw-CMR,代码行数:51,代码来源:RoleDAO.scala


示例20: UserDAOImpl

//设置package包名称以及导入依赖的类
package dao


import javax.inject.Inject
import model.User
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.concurrent.Execution.Implicits._
import javax.inject.Inject
import javax.inject.Singleton
import model.User
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.Future




@Singleton
class UserDAOImpl @Inject()(dbConfigProvider: DatabaseConfigProvider)(ec: ExecutionContext) extends UserDAO {

private val dbConfig  = dbConfigProvider.get[JdbcProfile]


  import dbConfig._
  import driver.api._

  private class UserTable(tag:Tag)
    extends Table[User](tag, "user") {
    def id = column[Long]("id", O.PrimaryKey,O.AutoInc)
    def firstName = column[String]("first_name")
    def lastName = column[String]("last_name")
    def mobile = column[Long]("mobile")
    def email = column[String]("email")

    override def * =
      (id, firstName,lastName,mobile,email) <> (User.tupled, User.unapply)
  }

  private val users = TableQuery[UserTable]

  override def add(user: User): Future[String] = {
    db.run(users += user).map(res => "User successfully added").recover {
      case ex : Exception => ex.getCause.getMessage
    }
  }

  override def delete(id: Long): Future[Int] = {
    db.run(users.filter(_.id === id).delete)
  }

  override def get(id: Long): Future[Option[User]] = {
    db.run(users.filter(_.id === id).result.headOption)
  }

  override def listAll: Future[Seq[User]] = {
    db.run(users.result)
  }

} 
开发者ID:vdudi,项目名称:play-slick-mysql,代码行数:62,代码来源:UserDAOImpl.scala



注:本文中的play.api.db.slick.DatabaseConfigProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Logger类代码示例发布时间:2022-05-23
下一篇:
Scala Request类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap