本文整理汇总了Scala中slick.jdbc.PostgresProfile类的典型用法代码示例。如果您正苦于以下问题:Scala PostgresProfile类的具体用法?Scala PostgresProfile怎么用?Scala PostgresProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PostgresProfile类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Repository
//设置package包名称以及导入依赖的类
package com.xebia.slick.repository
import slick.jdbc.PostgresProfile.api._
import Coffees._
import Suppliers._
import slick.jdbc.PostgresProfile
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}
object Repository {
val db: PostgresProfile.backend.Database = Database.forConfig("slick-db")
val schema = coffees.schema ++ suppliers.schema
def resetSchema: Future[Unit] = {
implicit val ec = scala.concurrent.ExecutionContext.global
val triedSession = Try(db.createSession())
val dropResults = (Try(Seq[String]()) /: schema.dropStatements.map { statement =>
val triedMesg = triedSession.flatMap(session => Try(session.prepareInsertStatement(statement).executeUpdate())).map(res => s"$statement").recoverWith {
case err if err.getMessage.contains("does not exist") => Success[String](s"Drop ignored: $err")
case err => Failure[String](err)
}
triedMesg
}.toSeq) { (trySeqStr, tryStr ) =>
trySeqStr flatMap (seqStr => tryStr map (str => seqStr :+ str))
}
triedSession.flatMap(session => Try(session.close()))
dropResults match {
case Failure(err) =>
Future.failed(err)
case Success(dropMessages) =>
//DEBUG: display statements
println("Initialising DB schema with:")
dropMessages.foreach(println)
schema.create.statements.foreach(println)
db.run(schema.create)
}
}
}
开发者ID:fagossa,项目名称:xke-slick_doobie,代码行数:46,代码来源:Repository.scala
示例2: createEnumArrayJdbcType
//设置package包名称以及导入依赖的类
package com.github.stonexx.slick.pg
import com.github.tminglei.slickpg.{PgEnumSupportUtils, PgEnumSupport}
import com.github.tminglei.slickpg.utils.SimpleArrayUtils
import slick.jdbc.{PostgresProfile, JdbcType}
import scala.reflect.ClassTag
trait PgEnumSupportFixed extends PgEnumSupport { self: PostgresProfile =>
import PgEnumSupportUtils.sqlName
def createEnumArrayJdbcType[T <: Enumeration](sqlEnumTypeName: String, enumObject: T, quoteName: Boolean = false): AdvancedArrayJdbcType[enumObject.Value] =
createEnumArrayJdbcType[enumObject.Value](sqlEnumTypeName, _.toString, s => enumObject.withName(s), quoteName)
def createEnumArrayJdbcType[T: ClassTag](sqlEnumTypeName: String, enumToString: (T => String), stringToEnum: (String => T), quoteName: Boolean) =
new AdvancedArrayJdbcType[T](sqlName(sqlEnumTypeName, quoteName),
fromString = s => SimpleArrayUtils.fromString(s1 => stringToEnum(s1))(s).orNull,
mkString = v => SimpleArrayUtils.mkString[T](enumToString)(v)
)
def createEnumJdbcTypeWithArrayJdbcType[T <: Enumeration](sqlEnumTypeName: String, enumObject: T, quoteName: Boolean = false)(implicit tag: ClassTag[enumObject.Value]): (JdbcType[enumObject.Value], AdvancedArrayJdbcType[enumObject.Value]) = {
createEnumJdbcTypeWithArrayJdbcType[enumObject.Value](sqlEnumTypeName, _.toString, s => enumObject.withName(s), quoteName)
}
def createEnumJdbcTypeWithArrayJdbcType[T: ClassTag](sqlEnumTypeName: String, enumToString: (T => String), stringToEnum: (String => T), quoteName: Boolean): (JdbcType[T], AdvancedArrayJdbcType[T]) = {
(createEnumJdbcType(sqlEnumTypeName, enumToString, stringToEnum, quoteName), createEnumArrayJdbcType(sqlEnumTypeName, enumToString, stringToEnum, quoteName))
}
}
开发者ID:stonexx,项目名称:utils,代码行数:29,代码来源:PgEnumSupportFixed.scala
示例3: currentJdbcProfile
//设置package包名称以及导入依赖的类
package db
import slick.jdbc.{JdbcProfile, PostgresProfile}
import currentJdbcProfile.profile
private[db] sealed trait DatabaseConfigProvider[P <: JdbcProfile] {
val db: P#Backend#Database
}
private[db] trait JdbcDatabaseConfigProvider extends DatabaseConfigProvider[profile.type] {
import currentJdbcProfile.api.Database
override lazy val db = Database.forConfig("database")
}
private[db] object currentJdbcProfile {
val profile = PostgresProfile
lazy val api = profile.api
}
开发者ID:kkrzys,项目名称:eShop,代码行数:20,代码来源:DatabaseConfigProvider.scala
注:本文中的slick.jdbc.PostgresProfile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论