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

Scala HasDatabaseConfig类代码示例

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

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



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

示例1: 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


示例2: OAuthApp

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


import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import slick.driver.JdbcProfile
import models.dao.PortableJodaSupport._
import driver.api._
import dao._
import org.joda.time.{DateTime, DateTimeZone}
import play.api.Play
import play.api.Play.current

import scala.concurrent.Future

import utils.StringUtils

case class OAuthApp(
    id:            String           = StringUtils.generateUuid,
    created_at:    DateTime         = DateTime.now(DateTimeZone.UTC),
    deleted_at:    Option[DateTime] = None,
    client_id:     String           = StringUtils.generateUuid,
    client_secret: String           = StringUtils.generateUuid,
    name:          String,
    redirect_url:  Option[String]   = None
)

class OAuthAppTable(tag: Tag) extends Table[OAuthApp](tag, "oauth_app") {
  val id = column[String]("id", O.PrimaryKey)
  val created_at = column[DateTime]("created_at")
  val deleted_at = column[Option[DateTime]]("deleted_at")
  val client_id = column[String]("client_id")
  val client_secret = column[String]("client_secret")
  val name = column[String]("name")
  val redirect_url = column[Option[String]]("redirect_url")

  def * = (id, created_at, deleted_at, client_id, client_secret, name, redirect_url) <> ((OAuthApp.apply _).tupled, OAuthApp.unapply _)
}

class OAuthApps extends HasDatabaseConfig[JdbcProfile] {

  protected val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
  val tables = TableQuery[OAuthAppTable]

  //---------------
  //Methods
  //---------------

  def findByClientId(client_id: String): Future[Option[OAuthApp]] = {
    db.run(tables.filter(_.client_id === client_id).result.headOption)
  }

}

trait OAuthAppsAware {
  implicit lazy val appManagerDao: OAuthApps = new OAuthApps()
} 
开发者ID:Driox,项目名称:oauth-provider-seed,代码行数:58,代码来源:OAuthApp.scala


示例3: dateTimeMapper

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

import java.sql.Timestamp

import com.netaporter.uri.Uri
import org.joda.time.DateTime
import slick.driver.JdbcProfile
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import play.api.Play
import repository.user.{Female, Gender, Male}



trait ColumnTypeMapper extends HasDatabaseConfig[JdbcProfile] {
  protected val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
  import driver.api._

  implicit def dateTimeMapper = {
    MappedColumnType.base[DateTime, Timestamp] (
      dt => new Timestamp(dt.getMillis),
      ts => new DateTime(ts.getTime)
    )
  }

  implicit def dateTimeOrdering: Ordering[DateTime] = Ordering.fromLessThan(_ isBefore _)

  implicit def uriMapper = MappedColumnType.base[Uri, String] (
    dt => dt.toString(),
    ts => Uri.parse(ts)
  )

  implicit def genderMapper = MappedColumnType.base[Gender, String] (
    {
      case Male => "male"
      case Female => "female"
    },
    {
      case "male" => Male
      case "female" => Female
    }
  )
} 
开发者ID:marius-carp,项目名称:should-i-api,代码行数:44,代码来源:ColumnTypeMapper.scala


示例4: Sample

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

import play.api.Play
import slick.driver.MySQLDriver.api._

import scala.concurrent.Future
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import slick.driver.JdbcProfile

case class Sample(id: Option[Int], name: String)

trait SamplesTable {
  class Samples(tag: Tag) extends Table[Sample](tag, "SAMPLE") {
    def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
    def name = column[String]("NAME")
    def * = (id.?, name) <> (Sample.tupled, Sample.unapply)
  }
  val samples = TableQuery[Samples]
}

object SamplesDAO extends HasDatabaseConfig[JdbcProfile] with SamplesTable {
  val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)

  def findById(id: Int): Future[Option[Sample]] =
    db.run(samples.filter(_.id === id).result.headOption)

  def findAll: Future[Seq[Sample]] =
    db.run(samples.result)

  def insert(newRecord: Sample): Future[Int] = {
    db.run((samples returning samples.map(_.id)) += newRecord)
  }

  def update(record: Sample): Future[Int] = {
    db.run(samples.filter(_.id === record.id)
      .map(a => (a.name))
      .update((record.name)))
  }

} 
开发者ID:kaznishi,项目名称:zz-sandbox-slackbot-sample,代码行数:42,代码来源:SamplesDAO.scala


示例5: dateTimeMapper

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

import java.sql.Timestamp
import com.netaporter.uri.Uri
import org.joda.time.DateTime
import slick.driver.JdbcProfile
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import play.api.Play
import slick.backend.DatabaseConfig


trait ColumnTypeMapper extends HasDatabaseConfig[JdbcProfile] {
  protected val dbConfig: DatabaseConfig[JdbcProfile] = DatabaseConfigProvider.get[JdbcProfile](Play.current)
  import driver.api._

  implicit def dateTimeMapper = {
    MappedColumnType.base[DateTime, Timestamp] (
      dt => new Timestamp(dt.getMillis),
      ts => new DateTime(ts.getTime)
    )
  }

  implicit def dateTimeOrdering: Ordering[DateTime] = Ordering.fromLessThan(_ isBefore _)

  implicit def uriMapper = MappedColumnType.base[Uri, String] (
    dt => dt.toString(),
    ts => Uri.parse(ts)
  )
} 
开发者ID:marius-carp,项目名称:work-time-app,代码行数:31,代码来源:ColumnTypeMapper.scala


示例6: UserDAO

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

import play.api.Play
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfig}
import slick.driver.MySQLDriver
import scala.concurrent._
import play.api.libs.concurrent.Execution.Implicits.defaultContext


class UserDAO extends HasDatabaseConfig[MySQLDriver]  {

  val dbConfig = DatabaseConfigProvider.get[MySQLDriver](Play.current)

  import slick.driver.MySQLDriver.api._

  def all(): Future[Seq[UserRow]] = db.run(Tables.User.result)

  def findByEmail(email: String): Future[UserRow] = {
    val f = db.run(Tables.User.filter(_.email === email).result.headOption)
    f.map { result => result match {
      case Some(u) => u
      case None => throw new Exception("User not found")
    }}
  }
} 
开发者ID:cals80,项目名称:helloslick-play,代码行数:26,代码来源:UserDAO.scala


示例7: OptionFilter

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

import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import play.api.db.slick.HasDatabaseConfig
import play.api.Play
import database.tables._

trait DBComponentWithSlickQueryOps extends DBComponent {
 //databaseConfig: HasDatabaseConfig[ JdbcProfile ] =>

  import cats.Apply
  import cats.std.list._
 // import driver.api._
  import dbConfig.driver.api._

  type BooleanOp = ( Rep[ Boolean ], Rep[ Boolean ] ) => Rep[ Boolean ]

  implicit class OptionFilter[ X, Y ]( query: Query[ X, Y, Seq ] ) {

    
    def foundBy[ T ]( ops: List[ ( X ) => Option[ Rep[ Boolean ] ] ] )
                    ( f: BooleanOp ): Query[ X, Y, Seq ] =
      query.filter { q =>
        val res = Apply[ List ].ap( ops )( List( q ) ).collect { 
          case Some( y ) => y 
        } reduceLeftOption f
        res.getOrElse( false: Rep[ Boolean ] )
      } take 1
  }
} 
开发者ID:paulsmal,项目名称:zcrm-backend,代码行数:32,代码来源:DBComponentWithSlickQueryOps.scala


示例8: ApiLogService

//设置package包名称以及导入依赖的类
package domain.service

import javax.inject.Inject

import api.ApiRequestHeader
import api.ApiUtil._
import ApiToken._
import domain.models.Tables
import play.api.cache.CacheApi
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfig}
import play.api.libs.json.{JsNull, JsValue, Json}
import play.api.mvc.RequestHeader
import slick.driver.JdbcProfile



class ApiLogService @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends Tables with HasDatabaseConfig[JdbcProfile] {

  val dbConfig = dbConfigProvider.get[JdbcProfile]
  val profile = slick.driver.MySQLDriver

  import dbConfig.driver.api._

  def insert[R <: RequestHeader](status: Int, json: JsValue)(implicit cache: CacheApi,request: ApiRequestHeader[R]) = {

    val row = ApilogRow(
      datetime = currentTimestamp,
      ip = request.remoteAddress,
      token = request.maybeAuthToken,
      method = request.method,
      uri = request.uri,
      requestbody = request.maybeBody,
      responsestatus = status,
      responsebody = if (json == JsNull) None else Some(Json.prettyPrint(json)),
      email = getMaybeEmail(request.maybeAuthToken)
    )

    def token(implicit request: ApiRequestHeader[R]): String = {
      request.maybeAuthToken match {
        case Some(t) => t
        case None => EMPTY_STRING
      }
    }
    db.run(Apilog += row)
  }

} 
开发者ID:yuukiishikawa,项目名称:play-slick-restful-simple-api-seed,代码行数:48,代码来源:ApiLogService.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala ByteString类代码示例发布时间:2022-05-23
下一篇:
Scala Upstream5xxResponse类代码示例发布时间: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