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


Scala ProvenShape类代码示例

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


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

示例1: Suppliers

//设置package包名称以及导入依赖的类
import slick.driver.H2Driver.api._
import slick.lifted.{ProvenShape, ForeignKeyQuery}

// A Suppliers table with 6 columns: id, name, street, city, state, zip
class Suppliers(tag: Tag)
  extends Table[(Int, String, String, String, String, String)](tag, "SUPPLIERS") {

  // This is the primary key column:
  def id: Rep[Int] = column[Int]("SUP_ID", O.PrimaryKey)
  def name: Rep[String] = column[String]("SUP_NAME")
  def street: Rep[String] = column[String]("STREET")
  def city: Rep[String] = column[String]("CITY")
  def state: Rep[String] = column[String]("STATE")
  def zip: Rep[String] = column[String]("ZIP")
  
  // Every table needs a * projection with the same type as the table's type parameter
  def * : ProvenShape[(Int, String, String, String, String, String)] =
    (id, name, street, city, state, zip)
}

// A Coffees table with 5 columns: name, supplier id, price, sales, total
class Coffees(tag: Tag)
  extends Table[(String, Int, Double, Int, Int)](tag, "COFFEES") {

  def name: Rep[String] = column[String]("COF_NAME", O.PrimaryKey)
  def supID: Rep[Int] = column[Int]("SUP_ID")
  def price: Rep[Double] = column[Double]("PRICE")
  def sales: Rep[Int] = column[Int]("SALES")
  def total: Rep[Int] = column[Int]("TOTAL")
  
  def * : ProvenShape[(String, Int, Double, Int, Int)] =
    (name, supID, price, sales, total)
  
  // A reified foreign key relation that can be navigated to create a join
  def supplier: ForeignKeyQuery[Suppliers, (Int, String, String, String, String, String)] = 
    foreignKey("SUP_FK", supID, TableQuery[Suppliers])(_.id)
} 
开发者ID:jtonic,项目名称:handson-slick,代码行数:38,代码来源:Tables.scala

示例2: LocalDateTimeColumnType

//设置package包名称以及导入依赖的类
package com.dbrsn.datatrain.slick

import java.time.LocalDateTime

import cats.~>
import com.dbrsn.datatrain.dsl.meta.ResourceDSL
import com.dbrsn.datatrain.dsl.meta.ResourceDSL.Create
import com.dbrsn.datatrain.model.Resource
import com.dbrsn.datatrain.model.ResourceId
import shapeless.Generic
import shapeless.HNil
import slick.jdbc.JdbcProfile
import slick.lifted.ProvenShape
import slickless._

case class LocalDateTimeColumnType[P <: JdbcProfile](implicit columnType: P#BaseColumnType[LocalDateTime])

trait ResourceJdbcComponent[P <: JdbcProfile] {

  val localDateTimeColumnType: LocalDateTimeColumnType[P]
  val profile: P

  import profile.api._
  import localDateTimeColumnType._

  type ResourceJdbcDSL[A] = ResourceDSL[A]

  def resourceTableName: String = "dt_resource"

  class ResourceTable(tag: Tag) extends Table[Resource](tag, resourceTableName) {
    def id: Rep[ResourceId] = column[ResourceId]("id", O.PrimaryKey)
    def createdAt: Rep[LocalDateTime] = column[LocalDateTime]("created_at")

    override def * : ProvenShape[Resource] = (id :: createdAt :: HNil).mappedWith(Generic[Resource])
  }

  lazy val resourceTableQuery: TableQuery[ResourceTable] = TableQuery[ResourceTable]

  object ResourceInterpreter extends (ResourceJdbcDSL ~> DBIO) {
    override def apply[A](fa: ResourceJdbcDSL[A]): DBIO[A] = fa match {
      case Create(resource) => (resourceTableQuery returning resourceTableQuery.map(_.id) into ((v, _) => v)) += resource
    }
  }

} 
开发者ID:dborisenko,项目名称:data-train,代码行数:46,代码来源:ResourceJdbcComponent.scala

示例3: contentTableName

//设置package包名称以及导入依赖的类
package com.dbrsn.datatrain.slick

import java.time.LocalDateTime

import cats.~>
import com.dbrsn.datatrain.dsl.meta.ContentDSL
import com.dbrsn.datatrain.dsl.meta.ContentDSL.Create
import com.dbrsn.datatrain.model.Content
import com.dbrsn.datatrain.model.ContentId
import com.dbrsn.datatrain.model.ContentType
import com.dbrsn.datatrain.model.Resource
import com.dbrsn.datatrain.model.ResourceId
import shapeless.Generic
import shapeless.HNil
import slick.jdbc.JdbcProfile
import slick.lifted.ForeignKeyQuery
import slick.lifted.ProvenShape
import slickless._

trait ContentJdbcComponent[P <: JdbcProfile] {
  self: ResourceJdbcComponent[P] =>

  val profile: P

  import profile.api._
  import localDateTimeColumnType._

  type ContentJdbcDSL[A] = ContentDSL[A]

  def contentTableName: String = "dt_content"

  class ContentTable(tag: Tag) extends Table[Content](tag, contentTableName) {
    def id: Rep[ContentId] = column[ContentId]("id", O.PrimaryKey)
    def createdAt: Rep[LocalDateTime] = column[LocalDateTime]("created_at")
    def resourceId: Rep[ResourceId] = column[ResourceId]("resource_id")
    def contentType: Rep[Option[ContentType]] = column[Option[ContentType]]("content_type")
    def contentName: Rep[String] = column[String]("content_name")

    override def * : ProvenShape[Content] = (id :: createdAt :: resourceId :: contentType :: contentName :: HNil).mappedWith(Generic[Content])

    def resourceIdFk: ForeignKeyQuery[ResourceTable, Resource] = foreignKey(s"fk_${contentTableName}_resource_id", resourceId, resourceTableQuery)(_.id)
  }

  lazy val contentTableQuery: TableQuery[ContentTable] = TableQuery[ContentTable]

  object ContentInterpreter extends (ContentJdbcDSL ~> DBIO) {
    override def apply[A](fa: ContentJdbcDSL[A]): DBIO[A] = fa match {
      case Create(content) => (contentTableQuery returning contentTableQuery.map(_.id) into ((v, _) => v)) += content
    }
  }

} 
开发者ID:dborisenko,项目名称:data-train,代码行数:53,代码来源:ContentJdbcComponent.scala

示例4: contentMetadataTableName

//设置package包名称以及导入依赖的类
package com.dbrsn.datatrain.slick

import cats.~>
import com.dbrsn.datatrain.dsl.meta.ContentMetadataDSL
import com.dbrsn.datatrain.model.Content
import com.dbrsn.datatrain.model.ContentId
import com.dbrsn.datatrain.model.Metadata
import com.dbrsn.datatrain.model.MetadataKey
import com.dbrsn.datatrain.model.MetadataValue
import shapeless.Generic
import shapeless.HNil
import slick.jdbc.JdbcProfile
import slick.lifted.ForeignKeyQuery
import slick.lifted.ProvenShape
import slickless._

trait ContentMetadataJdbcComponent[P <: JdbcProfile] {
  self: ContentJdbcComponent[P] =>

  val profile: P
  val metadataKeyColumnType: MetadataKeyColumnType[P]

  import ContentMetadataDSL._
  import profile.api._
  import metadataKeyColumnType._

  type ContentMetadataJdbcDSL[A] = ContentMetadataDSL[A]

  def contentMetadataTableName: String = "dt_content_metadata"

  class ContentMetadataTable(tag: Tag) extends Table[Metadata[Content]](tag, contentMetadataTableName) {
    def id: Rep[ContentId] = column[ContentId]("id", O.PrimaryKey)
    def key: Rep[MetadataKey] = column[MetadataKey]("key")
    def value: Rep[MetadataValue] = column[MetadataValue]("value")

    override def * : ProvenShape[Metadata[Content]] = (id :: key :: value :: HNil).mappedWith(Generic[Metadata[Content]])

    def idFk: ForeignKeyQuery[ContentTable, Content] = foreignKey(s"fk_dt_${contentMetadataTableName}_id", id, contentTableQuery)(_.id)
  }

  lazy val contentMetadataTableQuery: TableQuery[ContentMetadataTable] = TableQuery[ContentMetadataTable]

  object ContentMetadataInterpreter extends (ContentMetadataJdbcDSL ~> DBIO) {
    override def apply[A](fa: ContentMetadataJdbcDSL[A]): DBIO[A] = fa match {
      case Create(metadata) => (contentMetadataTableQuery returning contentMetadataTableQuery.map(_.id) into ((v, _) => v)) += metadata
    }
  }

} 
开发者ID:dborisenko,项目名称:data-train,代码行数:50,代码来源:ContentMetadataJdbcComponent.scala

示例5: MetadataKeyColumnType

//设置package包名称以及导入依赖的类
package com.dbrsn.datatrain.slick

import cats.~>
import com.dbrsn.datatrain.dsl.meta.ResourceMetadataDSL
import com.dbrsn.datatrain.model.Metadata
import com.dbrsn.datatrain.model.MetadataKey
import com.dbrsn.datatrain.model.MetadataValue
import com.dbrsn.datatrain.model.Resource
import com.dbrsn.datatrain.model.ResourceId
import shapeless.Generic
import shapeless.HNil
import slick.jdbc.JdbcProfile
import slick.lifted.ForeignKeyQuery
import slick.lifted.ProvenShape
import slickless._

case class MetadataKeyColumnType[P <: JdbcProfile](implicit columnType: P#BaseColumnType[MetadataKey])

trait ResourceMetadataJdbcComponent[P <: JdbcProfile] {
  self: ResourceJdbcComponent[P] =>

  val profile: P
  val metadataKeyColumnType: MetadataKeyColumnType[P]

  import ResourceMetadataDSL._
  import profile.api._
  import metadataKeyColumnType._

  type ResourceMetadataJdbcDSL[A] = ResourceMetadataDSL[A]

  def resourceMetadataTableName: String = "dt_resource_metadata"

  class ResourceMetadataTable(tag: Tag) extends Table[Metadata[Resource]](tag, resourceMetadataTableName) {
    def id: Rep[ResourceId] = column[ResourceId]("id", O.PrimaryKey)
    def key: Rep[MetadataKey] = column[MetadataKey]("key")
    def value: Rep[MetadataValue] = column[MetadataValue]("value")

    override def * : ProvenShape[Metadata[Resource]] = (id :: key :: value :: HNil).mappedWith(Generic[Metadata[Resource]])

    def idFk: ForeignKeyQuery[ResourceTable, Resource] = foreignKey(s"fk_dt_${resourceMetadataTableName}_id", id, resourceTableQuery)(_.id)
  }

  lazy val resourceMetadataTableQuery: TableQuery[ResourceMetadataTable] = TableQuery[ResourceMetadataTable]

  object ResourceMetadataInterpreter extends (ResourceMetadataJdbcDSL ~> DBIO) {
    override def apply[A](fa: ResourceMetadataJdbcDSL[A]): DBIO[A] = fa match {
      case Create(metadata) => (resourceMetadataTableQuery returning resourceMetadataTableQuery.map(_.id) into ((v, _) => v)) += metadata
    }
  }

} 
开发者ID:dborisenko,项目名称:data-train,代码行数:52,代码来源:ResourceMetadataJdbcComponent.scala

示例6: Computers

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

import java.util.Date

import com.github.stonexx.slick.ext.{ExtJdbcProfile, HasSlickProfile}
import models.Computer
import slick.lifted.ProvenShape

trait ComputersComponent { this: HasSlickProfile[ExtJdbcProfile] with CommonComponent =>
  import profile.api._

  class Computers(tag: Tag) extends Table[Computer](tag, "COMPUTER") {

    def id: Rep[Long] = column[Long]("ID", O.PrimaryKey, O.AutoInc)
    def name: Rep[String] = column[String]("NAME")
    def introduced: Rep[Option[Date]] = column[Option[Date]]("INTRODUCED")
    def discontinued: Rep[Option[Date]] = column[Option[Date]]("DISCONTINUED")
    def companyId: Rep[Option[Long]] = column[Option[Long]]("COMPANY_ID")

    def * : ProvenShape[Computer] = (
      id.?, name, introduced, discontinued, companyId
    ) <> ((Computer.apply _).tupled, Computer.unapply)
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:25,代码来源:ComputersComponent.scala

示例7: Tests

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

import com.github.stonexx.slick.ext.HasSlickProfile
import models.Test
import slick.lifted.{ProvenShape, PrimaryKey}

trait TestsComponent { this: HasSlickProfile[MyPostgresProfile] =>
  import profile.api._

  class Tests(tag: Tag) extends Table[Test](tag, "tests") {

    def a: Rep[String] = column[String]("a")
    def b: Rep[String] = column[String]("b")
    def c: Rep[String] = column[String]("c")
    def d: Rep[String] = column[String]("d")

    def * : ProvenShape[Test] = (a, b, c, d) <> ((Test.apply _).tupled, Test.unapply)

    def pk: PrimaryKey = primaryKey("tests_pkey", (a, b))
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:22,代码来源:TestsComponent.scala

示例8: SecurityUserRepo

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

import authentication.models.{PasswordHash, SecurityUser, SecurityUserId}
import commons.models.{IdMetaModel, Login, Property}
import commons.repositories._
import commons.repositories.mappings.{JavaTimeDbMappings, LoginDbMappings}
import slick.dbio.DBIO
import slick.jdbc.MySQLProfile.api.{DBIO => _, MappedTo => _, Rep => _, TableQuery => _, _}
import slick.lifted.{ProvenShape, _}

private[authentication] class SecurityUserRepo(
                                                         override protected val dateTimeProvider: DateTimeProvider)
  extends BaseRepo[SecurityUserId, SecurityUser, SecurityUserTable]
    with AuditDateTimeRepo[SecurityUserId, SecurityUser, SecurityUserTable]
    with LoginDbMappings
    with SecurityUserDbMappings {

  def byLogin(login: Login): DBIO[Option[SecurityUser]] = {
    query
      .filter(_.login === login)
      .result
      .headOption
  }

  override protected val mappingConstructor: Tag => SecurityUserTable = new SecurityUserTable(_)

  override protected val modelIdMapping: BaseColumnType[SecurityUserId] = MappedColumnType.base[SecurityUserId, Long](
    vo => vo.value,
    id => SecurityUserId(id)
  )

  override protected val metaModel: IdMetaModel = SecurityUserMetaModel

  override protected val metaModelToColumnsMapping: Map[Property[_], (SecurityUserTable) => Rep[_]] = Map(
    SecurityUserMetaModel.id -> (table => table.id),
    SecurityUserMetaModel.login -> (table => table.login),
    SecurityUserMetaModel.password -> (table => table.password)
  )

}

protected class SecurityUserTable(tag: Tag) extends IdTable[SecurityUserId, SecurityUser](tag, "security_user")
  with AuditDateTimeTable
  with JavaTimeDbMappings
  with LoginDbMappings
  with SecurityUserDbMappings {

  def login: Rep[Login] = column("login")

  def password: Rep[PasswordHash] = column("password")

  def * : ProvenShape[SecurityUser] = (id, login, password, createdAt, modifiedAt) <> (SecurityUser.tupled,
    SecurityUser.unapply)
}

private[authentication] object SecurityUserMetaModel extends IdMetaModel {
  override type ModelId = SecurityUserId

  val login: Property[Login] = Property("login")
  val password: Property[PasswordHash] = Property("password")
} 
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:62,代码来源:SecurityUserRepo.scala

示例9: UserRepo

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

import javax.inject.Inject

import commons.models.{IdMetaModel, Login, Property}
import commons.repositories.mappings.LoginDbMappings
import commons.repositories.{BaseRepo, IdTable}
import slick.lifted.ProvenShape
import users.models.{User, UserId, UserMetaModel}
import slick.dbio.DBIO
import slick.jdbc.MySQLProfile.api.{DBIO => _, MappedTo => _, Rep => _, TableQuery => _, _}
import slick.lifted._

class UserRepo()
  extends BaseRepo[UserId, User, UserTable] {

  def byLogin(login: Login): DBIO[Option[User]] = {
    query
      .filter(_.login === login)
      .result
      .headOption
  }

  override protected val mappingConstructor: Tag => UserTable = new UserTable(_)

  override protected val modelIdMapping: BaseColumnType[UserId] = MappedColumnType.base[UserId, Long](
    vo => vo.value,
    id => UserId(id)
  )

  override protected val metaModel: IdMetaModel = UserMetaModel

  override protected val metaModelToColumnsMapping: Map[Property[_], (UserTable) => Rep[_]] = Map(
    UserMetaModel.id -> (table => table.id),
    UserMetaModel.login -> (table => table.login)
  )

  // TODO use shared login mapping
  implicit val loginMapping: BaseColumnType[Login] = MappedColumnType.base[Login, String](
    login => login.value,
    str => Login(str)
  )

}

protected class UserTable(tag: Tag) extends IdTable[UserId, User](tag, "user")
  with LoginDbMappings {
  def login: Rep[Login] = column[Login]("login")

  def * : ProvenShape[User] = (id, login) <> (User.tupled, User.unapply)
} 
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:52,代码来源:UserRepo.scala

示例10: Coffees

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

import freeslick.MSSQLServerProfile.api._
import slick.lifted.{ProvenShape, ForeignKeyQuery}

// A Coffees table with 5 columns: name, supplier id, price, sales, total
case class Coffees(tag: Tag)
  extends Table[(String, Int, Double, Int, Int)](tag, "COFFEES") {

  def name: Rep[String] = column[String]("COF_NAME", O.PrimaryKey)
  def supID: Rep[Int] = column[Int]("SUP_ID")
  def price: Rep[Double] = column[Double]("PRICE")
  def sales: Rep[Int] = column[Int]("SALES")
  def total: Rep[Int] = column[Int]("TOTAL")
  
  def * : ProvenShape[(String, Int, Double, Int, Int)] =
    (name, supID, price, sales, total)
  
  // A reified foreign key relation that can be navigated to create a join
  def supplier: ForeignKeyQuery[Suppliers, (Int, String, String, String, String, String)] = 
    foreignKey("SUP_FK", supID, TableQuery[Suppliers])(_.id)
} 
开发者ID:kametaro,项目名称:akka_slick_minimal_example,代码行数:23,代码来源:Coffees.scala

示例11: DAO

//设置package包名称以及导入依赖的类
import cog.ty.scraper.{Challenge, Difficulty, Response, User}
import slick.lifted.{ProvenShape, Tag}
import slick.jdbc.JdbcProfile
import java.util.Date
import java.net.URL

class DAO(driver: JdbcProfile) {
  import driver.api._

  class Users(tag: Tag) extends Table[User](tag, "USERS") {
    def username = column[String]("USERNAME", O.PrimaryKey)
    override def * : ProvenShape[User] = username <> (User.apply, User.unapply)
  }
  val users = TableQuery[Users]

  class Challenges(tag: Tag) extends Table[Challenge](tag, "CHALLENGES") {
    def id = column[String]("ID", O.PrimaryKey)
    def created = column[Date]("CREATED")
    def link = column[String]("LINK")
    def title = column[String]("TITLE")
    def body = column[String]("BODY")
    def difficulty = column[String]("DIFFICULTY")
    override def * : ProvenShape[Challenge] = (id, created, link, title, body, difficulty) <> (
      (row: (String, Date, String, String, String, String)) =>
          Challenge(row._1, row._2, new URL(row._3), row._4, row._5, Difficulty(row._6)),
      (ch: Challenge) =>
          Some(ch.id, ch.created, ch.link.toString, ch.title, ch.body, ch.difficulty.difficulty))
  }
  val challenges = TableQuery[Challenges]

  class Responses(tag: Tag) extends Table[(String, String, String, Date, Option[String], String)](tag, "RESPONSES") {
    def id = column[String]("ID", O.PrimaryKey)
    def challengeID = column[String]("CHALLENGE_ID")
    def username = column[String]("USERNAME")
    def created = column[Date]("CREATED")
    def link = column[Option[String]]("LINK")
    def body = column[String]("BODY")
    def challenge = foreignKey("CHALLENGE_ID", challengeID, challenges)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
    def user = foreignKey("USERNAME", username, users)(_.username, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
    override def * : (Rep[String], Rep[String], Rep[String], Rep[Date], Rep[Option[String]], Rep[String]) =
      (id, challengeID, username, created, link, body)
  }

  object responses extends TableQuery(new Responses(_)) {
    def insertRow(id: String, chId: String, uname: String, created: Date, link: Option[String], body: String) = {
      this += ((id, chId, uname, created, link, body))
    }
    val insertCompiled = Compiled(insertRow _)
//    def insertResponse(r: Response) = insertCompiled(r.id, r.challenge.id, r.user.username, r.created, r.link.map(_.toString), r.body)
  }
} 
开发者ID:Ophirr33,项目名称:daily-programmer-scraper,代码行数:52,代码来源:tables.scala

示例12: CitiesRepo

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

import com.google.inject.Inject
import models.City
import services.SqlDb
import slick.driver.H2Driver.api._
import slick.lifted.ProvenShape

class CitiesRepo @Inject()(sqlDb: SqlDb){

  val table = TableQuery[Cities]

  class Cities(tag: Tag) extends Table[City](tag, "cities"){
    def id: Rep[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
    def name: Rep[String] = column[String]("city")
    def country: Rep[String] = column[String]("country")

    override def * : ProvenShape[City] = (id, name, country) <> (City.tupled, City.unapply)
  }

  def byId(id: Int) = sqlDb.run(table.filter(_.id === id).result.head)
  def allCities = sqlDb.run(table.result)
} 
开发者ID:rok21,项目名称:kc_web,代码行数:24,代码来源:CitiesRepo.scala

示例13: IncomeOutcomeDAO

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

import java.sql.Date
import javax.inject.Inject

import models.{IncomeOutcome, User}
import play.api.db.slick.DatabaseConfigProvider
import play.db.NamedDatabase
import slick.backend.DatabaseConfig
import slick.driver.JdbcProfile
import slick.driver.SQLiteDriver.api._
import slick.lifted.{ForeignKeyQuery, ProvenShape}
import utils.Const

import scala.concurrent.{ExecutionContext, Future}

class IncomeOutcomeDAO @Inject()(@NamedDatabase(Const.DbName) dbConfigProvider: DatabaseConfigProvider,
                                 val userDAO: UserDAO)(implicit executionContext: ExecutionContext) {
  private val dbConfig: DatabaseConfig[JdbcProfile] = dbConfigProvider.get[JdbcProfile]
  // initialisation of foreign keys in SQLite
  dbConfig.db.run(DBIO.seq(sqlu"PRAGMA foreign_keys = ON;")).map { _ => () }

  private val incomesOutcomes: TableQuery[IncomeOutcomeTable] = TableQuery[IncomeOutcomeTable]

  def insert(incomeOutcome: IncomeOutcome): Future[Unit] = {
    dbConfig.db.run(incomesOutcomes += incomeOutcome).map { _ => () }
  }

  def findAll(userEmail: String): Future[Seq[IncomeOutcome]] = {
    dbConfig.db.run(incomesOutcomes.join(userDAO.users).on(_.userId === _.id).filter(_._2.email === userEmail)
      .map(_._1).result)
  }

  private class IncomeOutcomeTable(tag: Tag) extends Table[IncomeOutcome](tag, "income_outcome") {
    def id: Rep[Int] = column[Int]("id", O.PrimaryKey, O.AutoInc)
    def userId: Rep[Int] = column[Int]("userId")
    def date: Rep[Date] = column[Date]("date")
    def income: Rep[Double] = column[Double]("income")
    def outcome: Rep[Double] = column[Double]("outcome")

    // A reified foreign key relation to an user that can be navigated to create a join
    // n to one relationship
    def user: ForeignKeyQuery[userDAO.UserTable, User] = {
      // when an user is deleted, his income and outcome values are also deleted (same with update)
      foreignKey("user_FK", userId, userDAO.users)(_.id, onDelete = ForeignKeyAction.Cascade,
        onUpdate = ForeignKeyAction.Cascade)
    }

    def * : ProvenShape[IncomeOutcome] = {
      (date, income, outcome, userId) <> ((IncomeOutcome.apply _).tupled, IncomeOutcome.unapply)
    }
  }
} 
开发者ID:MathieuUrstein,项目名称:HEIG.SCALA.Projet,代码行数:54,代码来源:IncomeOutcomeDAO.scala

示例14: Suppliers

//设置package包名称以及导入依赖的类
import slick.driver.H2Driver.api._
import slick.lifted.{ ProvenShape, ForeignKeyQuery }

// A Suppliers table with 6 columns: id, name, street, city, state, zip
class Suppliers(tag: Tag)
    extends Table[(Int, String, String, String, String, String)](tag, "SUPPLIERS") {

  // This is the primary key column:
  def id: Rep[Int] = column[Int]("SUP_ID", O.PrimaryKey)
  def name: Rep[String] = column[String]("SUP_NAME")
  def street: Rep[String] = column[String]("STREET")
  def city: Rep[String] = column[String]("CITY")
  def state: Rep[String] = column[String]("STATE")
  def zip: Rep[String] = column[String]("ZIP")

  // Every table needs a * projection with the same type as the table's type parameter
  def * : ProvenShape[(Int, String, String, String, String, String)] =
    (id, name, street, city, state, zip)
}

// A Coffees table with 5 columns: name, supplier id, price, sales, total
class Coffees(tag: Tag)
    extends Table[(String, Int, Double, Int, Int)](tag, "COFFEES") {

  def name: Rep[String] = column[String]("COF_NAME", O.PrimaryKey)
  def supID: Rep[Int] = column[Int]("SUP_ID")
  def price: Rep[Double] = column[Double]("PRICE")
  def sales: Rep[Int] = column[Int]("SALES")
  def total: Rep[Int] = column[Int]("TOTAL")

  def * : ProvenShape[(String, Int, Double, Int, Int)] =
    (name, supID, price, sales, total)

  // A reified foreign key relation that can be navigated to create a join
  def supplier: ForeignKeyQuery[Suppliers, (Int, String, String, String, String, String)] =
    foreignKey("SUP_FK", supID, TableQuery[Suppliers])(_.id)
} 
开发者ID:rrramiro,项目名称:slick-imdb,代码行数:38,代码来源:Tables.scala

示例15: UserTokenMapping

//设置package包名称以及导入依赖的类
package auth.api.persistence

import java.sql.Timestamp
import java.time.LocalDateTime
import java.util.UUID

import auth.api.model.core.UserToken
import auth.api.model.core.UserToken.UserTokenAction
import auth.direct.persistence.HasAuthDbProfile
import auth.direct.persistence.model._
import slick.dbio.Effect._
import slick.lifted.ProvenShape

import scala.concurrent.ExecutionContext

trait TablesDefinitions
    extends ModelMappingSupport with CoreAuthTablesDefinitions with HasAuthDbProfile {
  import driver.api._

  sealed class UserTokenMapping(tag: Tag) extends Table[UserToken](tag, "userTokens") {
    def token: Rep[String]  = column[String]("token", O.PrimaryKey)
    def userUuid: Rep[UUID] = column[UUID]("users_uuid")
    // TODO: Localdatetime fails on postgres
    //def expiresOn: Rep[LocalDateTime] = column[LocalDateTime]("expireson")
    def expiresOn: Rep[Timestamp]         = column[Timestamp]("expiresOn")
    def tokenAction: Rep[UserTokenAction] = column[UserTokenAction]("tokenAction")

    def usersFk = foreignKey("fk_users_uuid", userUuid, usersQuery)(_.uuid)

    def from(x: UserToken): Option[(String, UUID, Timestamp, UserTokenAction)] = Some {
      (x.token, x.userUuid, Timestamp.valueOf(x.expiresOn), x.tokenAction)
    }

    def to(x: (String, UUID, Timestamp, UserTokenAction)): UserToken =
      UserToken(x._1, x._2, x._3.toLocalDateTime, x._4)

    override def * : ProvenShape[UserToken] =
      (token, userUuid, expiresOn, tokenAction) <> (to, from)
  }

  val userTokensQuery = TableQuery[UserTokenMapping]

  class Api()(implicit ec: ExecutionContext) extends super.Api()(ec) {
    object UserTokens {
      def issue(tokenHash: String,
                userUuid: UUID,
                action: UserTokenAction,
                forHours: Long): DBIOAction[UserToken, NoStream, Write] = {
        val token = UserToken(tokenHash, userUuid, LocalDateTime.now.plusHours(forHours), action)
        val act   = userTokensQuery += token
        act.map(_ ? token)
      }

      def find(token: String): DBIOAction[Option[UserToken], NoStream, Read] =
        userTokensQuery.filter(_.token === token).result.headOption

      def remove(token: String): DBIOAction[Boolean, NoStream, Write] =
        userTokensQuery.filter(_.token === token).delete.map(deleted ? deleted > 0)
    }
  }
} 
开发者ID:KadekM,项目名称:play-slick-silhouette-auth-api,代码行数:62,代码来源:TablesDefinitions.scala


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