本文整理汇总了Scala中slick.lifted.Rep类的典型用法代码示例。如果您正苦于以下问题:Scala Rep类的具体用法?Scala Rep怎么用?Scala Rep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rep类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ArrayLibrary
//设置package包名称以及导入依赖的类
package com.github.stonexx.slick.pg.array
import slick.ast.Library.SqlFunction
import slick.ast.{BaseTypedType, TypedType}
import slick.lifted.{Rep, Query}
import slick.lifted.FunctionSymbolExtensionMethods._
object ArrayLibrary {
val Array = new SqlFunction("array")
}
final class SingleColumnQueryExtensionMethods[B1, P1, C[_]](val q: Query[Rep[P1], _, C]) extends AnyVal {
def array(implicit tm: TypedType[C[B1]]): Rep[C[B1]] = ArrayLibrary.Array.column[C[B1]](q.toNode)
}
trait ExtensionMethodConversions {
implicit def pgArraySingleColumnQueryExtensionMethods[B1: BaseTypedType, C[_]](q: Query[Rep[B1], _, C]): SingleColumnQueryExtensionMethods[B1, B1, C] = new SingleColumnQueryExtensionMethods[B1, B1, C](q)
implicit def pgArraySingleOptionColumnQueryExtensionMethods[B1: BaseTypedType, C[_]](q: Query[Rep[Option[B1]], _, C]): SingleColumnQueryExtensionMethods[B1, Option[B1], C] = new SingleColumnQueryExtensionMethods[B1, Option[B1], C](q)
}
示例2: OrderedEnumerationUtils
//设置package包名称以及导入依赖的类
package com.github.stonexx.slick.ext.util
import com.github.stonexx.scala.data.{OrderedEnumeration, Ordering}
import slick.lifted.Rep
object OrderedEnumerationUtils {
def toSlickOrdered[E <: OrderedEnumeration](o: E#Ordered)(f: E#Value => Rep[_]) = new slick.lifted.Ordered(o.values.map {
case (v, ord) => (f(v).toNode, slick.ast.Ordering(
direction = ord.direction match {
case Ordering.Asc => slick.ast.Ordering.Asc
case Ordering.Desc => slick.ast.Ordering.Desc
},
nulls = ord.nulls match {
case Ordering.NullsDefault => slick.ast.Ordering.NullsDefault
case Ordering.NullsFirst => slick.ast.Ordering.NullsFirst
case Ordering.NullsLast => slick.ast.Ordering.NullsLast
}
))
})
}
示例3: RepoHelper
//设置package包名称以及导入依赖的类
package commons.repositories
import commons.models.{Ascending, Descending, Direction}
import slick.ast.{Ordering => SlickOrdering}
import slick.lifted.{ColumnOrdered, Rep}
object RepoHelper {
def createSlickColumnOrdered(column: Rep[_])(implicit direction: Direction): ColumnOrdered[_] = {
val slickDirection = toSlickDirection(direction)
ColumnOrdered(column, SlickOrdering(slickDirection))
}
private def toSlickDirection(direction: Direction): SlickOrdering.Direction = direction match {
case Ascending => SlickOrdering.Asc
case Descending => SlickOrdering.Desc
}
}
示例4: q
//设置package包名称以及导入依赖的类
package dao
import play.api.db.slick.HasDatabaseConfigProvider
import play.api.libs.concurrent.Execution.defaultContext
import slick.driver.H2Driver.api._
import slick.driver.JdbcProfile
import slick.lifted.{Rep, TableQuery}
import scala.concurrent.Future.successful
import scala.concurrent.{ExecutionContext, Future}
trait DefaultDAO[ID, E, Z <: Table[E]] extends BaseDAO[ID, E] with HasExecutionContext {
this: HasDatabaseConfigProvider[JdbcProfile] =>
// @formatter:off
def q: TableQuery[Z]
def filterIds(e: Seq[ID]): Query[Z, Z#TableElementType, Seq]
def getId(e: E): Option[ID]
def id(): Query[Rep[ID], ID, Seq]
// @formatter:on
def insertSeq(e: Seq[E]): Future[Seq[ID]] =
if (e.nonEmpty) db.run(((q returning id()) ++= e).transactionally) else successful(Seq.empty[ID])
def insertForce(e: Seq[E]): Future[Unit] =
if (e.nonEmpty) db.run((q ++= e).transactionally) map (_ => ()) else successful((): Unit)
def delete(): Future[Int] =
db.run(q.delete.transactionally)
def delete(ids: Seq[ID]): Future[Int] =
if (ids.nonEmpty) db.run(filterIds(ids).delete.transactionally) else successful(0)
def update(e: E): Future[Int] =
getId(e).fold(successful(0))(id => db.run(filterIds(id :: Nil).update(e).transactionally))
def seq(offset: Int, limit: Int): Future[Seq[E]] =
db.run(q.drop(offset).take(limit).result.transactionally)
def byId(e: Seq[ID]): Future[Seq[E]] =
db.run(filterIds(e).result.transactionally)
def count(): Future[Int] =
db.run(q.countDistinct.result.transactionally)
def whereOne(f: Z => Rep[Boolean]): Future[E] =
whereSeq(f) map (_.head)
def whereOpt(f: Z => Rep[Boolean]): Future[Option[E]] =
whereSeq(f) map (_.headOption)
def whereSeq(f: Z => Rep[Boolean]): Future[Seq[E]] =
db.run(q.filter(f).result.transactionally)
// play execution context by default
implicit def executionContext: ExecutionContext = defaultContext
}