本文整理汇总了Scala中slick.lifted.ProvenShape类的典型用法代码示例。如果您正苦于以下问题:Scala ProvenShape类的具体用法?Scala ProvenShape怎么用?Scala ProvenShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProvenShape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Rep1653283549 = column1653283549("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
示例16: BlockComponent
//设置package包名称以及导入依赖的类
package components
import com.google.inject.Inject
import dao.BlockDao
import dao.common.Repository
import models.Block
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile
import slick.lifted.ProvenShape
import scala.concurrent.{ExecutionContext, Future}
class BlockComponent @Inject()(
protected val dbConfigProvider: DatabaseConfigProvider,
protected val postComponent: PostComponent
) extends HasDatabaseConfigProvider[JdbcProfile] {
import profile.api._
class BlocksTable(tag: Tag) extends Table[Block](tag, "BLOCKS") {
private[components] def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
private[components] def postId = column[Long]("POST_ID")
private[components] def text = column[String]("TEXT")
private[components] def dialect = column[String]("DIALECT")
private[components] def prevId = column[Long]("PREV_ID")
// $COVERAGE-OFF$
private[components] def postFk = foreignKey("POST_FK", postId, postComponent.Posts)(
_.id,
onUpdate = ForeignKeyAction.NoAction,
onDelete = ForeignKeyAction.NoAction
)
// $COVERAGE-ON$
def * : ProvenShape[Block] = (id.?, postId.?, text, dialect, prevId.?) <> (Block.tupled, Block.unapply)
}
object Repository extends Repository[BlocksTable, Block](profile, db) with BlockDao {
override def table: profile.api.TableQuery[BlocksTable] = TableQuery[BlocksTable]
override def getId(row: BlocksTable): profile.api.Rep[Long] = row.id
override def deleteById(id: Long)(implicit exc: ExecutionContext): Future[Int] =
db.run(table.filter(getId(_) === id).delete)
override def findByPostId(postId: Long): Future[Seq[Block]] =
db.run(table.filter(_.postId === postId).result)
}
}
开发者ID:edgarmueller,项目名称:plog-backend,代码行数:52,代码来源:BlockComponent.scala
示例17: PostComponent
//设置package包名称以及导入依赖的类
package components
import java.sql.Date
import com.google.inject.Inject
import dao.PostDao
import dao.common.Repository
import models.Post
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile
import slick.lifted.ProvenShape
import scala.concurrent.{ExecutionContext, Future}
class PostComponent @Inject()(protected val dbConfigProvider: DatabaseConfigProvider,
protected val userComponent: UserComponent)
extends HasDatabaseConfigProvider[JdbcProfile] {
import profile.api._
object Posts extends TableQuery[PostsTable](tag => new PostsTable(tag)) {
private[components] def all = Posts.result
}
class PostsTable(tag: Tag) extends Table[Post](tag, "POSTS") {
private[components] def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
private[components] def title = column[String]("TITLE")
private[components] def authorId = column[Long]("AUTHOR_ID")
// TODO: rename to 'last modified/update date'
private[components] def date = column[Date]("PUBLISH_DATE")
// TODO: remove draft
private[components] def isDraft = column[Boolean]("IS_DRAFT")
// $COVERAGE-OFF$
private[components] def userFk = foreignKey("USER_FK", authorId, userComponent.Users)(
_.userId,
onUpdate = ForeignKeyAction.NoAction,
onDelete = ForeignKeyAction.NoAction
)
// $COVERAGE-ON$
def * : ProvenShape[Post] = (id.?, authorId.?, title, date, isDraft) <> (Post.tupled, Post.unapply)
}
object Repository extends Repository[PostsTable, Post](profile, db) with PostDao {
override def table: profile.api.TableQuery[PostsTable] = TableQuery[PostsTable]
override def getId(row: PostsTable): profile.api.Rep[Long] = row.id
override def deleteById(id: Long)(implicit exc: ExecutionContext): Future[Int] =
db.run(table.filter(getId(_) === id).delete)
def findByUserId(userId: Option[Long])(implicit exc: ExecutionContext): Future[Seq[Post]] = {
userId.fold(Future(Seq.empty[Post]))(id =>
db.run(Posts.filter(post => post.authorId === id).result)
)
}
}
}
开发者ID:edgarmueller,项目名称:plog-backend,代码行数:61,代码来源:PostComponent.scala
示例18: OauthAccessToken
//设置package包名称以及导入依赖的类
package models
import java.sql.Timestamp
import com.github.tototoshi.slick.MySQLJodaSupport._
import org.joda.time.DateTime
import slick.driver.MySQLDriver.api._
import slick.lifted.{ForeignKeyQuery, ProvenShape, TableQuery, Tag}
case class OauthAccessToken(
id: Long,
accountId: Long,
oauthClientId: Long,
accessToken: String,
refreshToken: String,
createdAt: DateTime
)
class OauthAccessTokenTableDef(tag: Tag) extends Table[OauthAccessToken](tag, "oauth_access_token") {
implicit def dateTime =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime)
)
val accounts: TableQuery[AccountTableDef] = TableQuery[AccountTableDef]
val clients: TableQuery[OauthClientTableDef] = TableQuery[OauthClientTableDef]
def id: Rep[Long] = column[Long]("id", O.PrimaryKey, O.AutoInc)
def accountId: Rep[Long] = column[Long]("account_id")
def oauthClientId: Rep[Long] = column[Long]("oauth_client_id")
def accessToken: Rep[String] = column[String]("access_token")
def refreshToken: Rep[String] = column[String]("refresh_token")
def createdAt: Rep[DateTime] = column[DateTime]("created_at")
def account: ForeignKeyQuery[AccountTableDef, Account] = foreignKey("oauth_access_token_account_id_fkey", accountId, accounts)(_.id)
def client: ForeignKeyQuery[OauthClientTableDef, OauthClient] = foreignKey("oauth_access_token_oauth_client_id_fkey", oauthClientId, clients)(_.id)
override def * : ProvenShape[OauthAccessToken] = (id, accountId, oauthClientId, accessToken, refreshToken, createdAt) <> ((OauthAccessToken.apply _).tupled, OauthAccessToken.unapply)
}
开发者ID:naveenwashere,项目名称:scala-oauth2-provider-slick,代码行数:41,代码来源:OAuthAccessToken.scala
示例19: OauthAuthorizationCode
//设置package包名称以及导入依赖的类
package models
import java.sql.Timestamp
import com.github.tototoshi.slick.MySQLJodaSupport._
import org.joda.time.DateTime
import slick.driver.MySQLDriver.api._
import slick.lifted.{ForeignKeyQuery, ProvenShape, TableQuery, Tag}
case class OauthAuthorizationCode(
id: Long,
accountId: Long,
oauthClientId: Long,
code: String,
redirectUri: Option[String],
createdAt: DateTime)
class OauthAuthorizationCodeTableDef(tag: Tag) extends Table[OauthAuthorizationCode](tag, "oauth_authorization_code") {
implicit def dateTime =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime)
)
val accounts: TableQuery[AccountTableDef] = TableQuery[AccountTableDef]
val clients: TableQuery[OauthClientTableDef] = TableQuery[OauthClientTableDef]
def id: Rep[Long] = column[Long]("id", O.PrimaryKey, O.AutoInc)
def accountId: Rep[Long] = column[Long]("account_id")
def oauthClientId: Rep[Long] = column[Long]("oauth_client_id")
def code: Rep[String] = column[String]("code")
def redirectUri: Rep[Option[String]] = column[Option[String]]("redirect_uri")
def createdAt: Rep[DateTime] = column[DateTime]("created_at")
def account: ForeignKeyQuery[AccountTableDef, Account] = foreignKey("oauth_authorization_owner_id_fkey", accountId, accounts)(_.id)
def client: ForeignKeyQuery[OauthClientTableDef, OauthClient] = foreignKey("oauth_authorization_client_id_fkey", oauthClientId, clients)(_.id)
def * : ProvenShape[OauthAuthorizationCode] = (id, accountId, oauthClientId, code, redirectUri, createdAt) <> ((OauthAuthorizationCode.apply _).tupled, OauthAuthorizationCode.unapply)
}
开发者ID:naveenwashere,项目名称:scala-oauth2-provider-slick,代码行数:40,代码来源:OAuthAuthorizationCode.scala
示例20: OauthClient
//设置package包名称以及导入依赖的类
package models
import java.sql.Timestamp
import org.joda.time.DateTime
import slick.driver.MySQLDriver.api._
import slick.lifted.{ForeignKeyQuery, ProvenShape, TableQuery, Tag}
case class OauthClient(
id: Long,
ownerId: Long,
grantType: String,
clientId: String,
clientSecret: String,
redirectUri: Option[String],
createdAt: DateTime
)
class OauthClientTableDef(tag: Tag) extends Table[OauthClient](tag, "oauth_client") {
implicit def dateTime =
MappedColumnType.base[DateTime, Timestamp](
dt => new Timestamp(dt.getMillis),
ts => new DateTime(ts.getTime)
)
val accounts: TableQuery[AccountTableDef] = TableQuery[AccountTableDef]
def id: Rep[Long] = column[Long]("id", O.PrimaryKey, O.AutoInc)
def ownerId: Rep[Long] = column[Long]("owner_id")
def grantType: Rep[String] = column[String]("grant_type")
def clientId: Rep[String] = column[String]("client_id")
def clientSecret: Rep[String] = column[String]("client_secret")
def redirectUri: Rep[Option[String]] = column[Option[String]]("redirect_uri")
def createdAt: Rep[DateTime] = column[DateTime]("created_at")
def account: ForeignKeyQuery[AccountTableDef, Account] = foreignKey("oauth_client_owner_id_fkey", ownerId, accounts)(_.id)
def * : ProvenShape[OauthClient] = (id, ownerId, grantType, clientId, clientSecret, redirectUri, createdAt) <> ((OauthClient.apply _).tupled, OauthClient.unapply)
}
开发者ID:naveenwashere,项目名称:scala-oauth2-provider-slick,代码行数:40,代码来源:OAuthClient.scala
注:本文中的slick.lifted.ProvenShape类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论