当前位置: 首页>>代码示例>>Scala>>正文


Scala Rep类代码示例

本文整理汇总了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)
} 
开发者ID:stonexx,项目名称:utils,代码行数:20,代码来源:ExtensionMethods.scala

示例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
      }
    ))
  })
} 
开发者ID:stonexx,项目名称:utils,代码行数:22,代码来源:OrderedEnumerationUtils.scala

示例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
  }
} 
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:18,代码来源:RepoHelper.scala

示例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
} 
开发者ID:ximagination80,项目名称:play2.4-slick3-baseSlickDao,代码行数:58,代码来源:DefaultDAO.scala


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