本文整理汇总了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)
}
}
}
示例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))
}
}
示例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
}