本文整理汇总了Scala中slick.lifted.ForeignKeyQuery类的典型用法代码示例。如果您正苦于以下问题:Scala ForeignKeyQuery类的具体用法?Scala ForeignKeyQuery怎么用?Scala ForeignKeyQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ForeignKeyQuery类的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: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: DownInformations
//设置package包名称以及导入依赖的类
package dao
import models._
import slick.lifted.{ForeignKeyQuery, Tag}
import slick.driver.H2Driver.api._
class DownInformations(tag: Tag) extends Table[DownInformation](tag, "down_informations") {
def id: Rep[Int] = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name: Rep[String] = column[String]("name")
def down: Rep[Int] = column[Int]("down")
def yards: Rep[Int] = column[Int]("yards")
def gained: Rep[Int] = column[Int]("gained")
def playId: Rep[Int] = column[Int]("play_id")
def targetId: Rep[Int] = column[Int]("target_id")
def formationId: Rep[Int] = column[Int]("formation_id")
def gameId: Rep[Int] = column[Int]("game_id")
def * = (id.?, name, down, yards, gained, formationId, playId, targetId, gameId) <> ((DownInformation.apply _).tupled, DownInformation.unapply)
def formationFk: ForeignKeyQuery[Formations, Formation] = foreignKey("formation", formationId, Formations.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
def playFk: ForeignKeyQuery[PlayInformations, PlayInformation] = foreignKey("play", playId, PlayInformations.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
def targetFk: ForeignKeyQuery[Players, Player] = foreignKey("target", targetId, Players.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
def gameFk: ForeignKeyQuery[Games, Game] = foreignKey("game", gameId, Games.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
}
// def supplier = foreignKey("SUP_FK", supID, suppliers)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
object DownInformations {
val objects: TableQuery[DownInformations] = TableQuery[DownInformations]
}
开发者ID:vililahtevanoja,项目名称:Predator-App-Server,代码行数:27,代码来源:DownInformations.scala
示例9: Games
//设置package包名称以及导入依赖的类
package dao
import models.{Game, Team}
import slick.driver.H2Driver.api._
import slick.lifted.{ForeignKeyQuery, Tag}
import java.sql.Date
class Games(tag: Tag) extends Table[Game](tag, "games") {
def id: Rep[Int] = column[Int]("id", O.PrimaryKey, O.AutoInc)
def homeTeamId: Rep[Int] = column[Int]("home_team_id")
def visitorTeamId: Rep[Int] = column[Int]("visitor_team_id")
def date: Rep[Date] = column[Date]("date")
def * = (id.?, homeTeamId, visitorTeamId, date) <> ((Game.apply _).tupled, Game.unapply)
def homeTeamFk: ForeignKeyQuery[Teams, Team] = foreignKey("home_team", homeTeamId, Teams.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
def visitorTeamFk: ForeignKeyQuery[Teams, Team] = foreignKey("visitor_team", visitorTeamId, Teams.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
}
object Games {
val objects: TableQuery[Games] = TableQuery[Games]
}
开发者ID:vililahtevanoja,项目名称:Predator-App-Server,代码行数:22,代码来源:Games.scala
示例10: PlayInformations
//设置package包名称以及导入依赖的类
package dao
import models.{PlayInformation, PlayType}
import slick.lifted.{ForeignKeyQuery, Tag}
import slick.driver.H2Driver.api._
class PlayInformations(tag: Tag) extends Table[PlayInformation](tag, "play_informations") {
val id: Rep[Int] = column[Int]("id", O.PrimaryKey, O.AutoInc)
val name: Rep[String] = column[String]("name")
val playTypeId: Rep[Int] = column[Int]("playtype_id")
def * = (id.?, name, playTypeId) <> ((PlayInformation.apply _).tupled, PlayInformation.unapply)
val playType: ForeignKeyQuery[PlayTypes, PlayType] = foreignKey("playType", playTypeId, PlayTypes.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
}
object PlayInformations {
val objects: TableQuery[PlayInformations] = TableQuery[PlayInformations]
}
开发者ID:vililahtevanoja,项目名称:Predator-App-Server,代码行数:18,代码来源:PlayInformations.scala
示例11: Players
//设置package包名称以及导入依赖的类
package dao
import models.{Player, Team}
import slick.driver.H2Driver.api._
import slick.lifted.{ForeignKeyQuery, Tag}
class Players(tag: Tag) extends Table[Player](tag, "players") {
val id: Rep[Int] = column[Int]("id", O.PrimaryKey, O.AutoInc)
val number: Rep[Int] = column[Int]("number")
val teamId: Rep[Int] = column[Int]("team_id")
def * = (id.?, number, teamId) <> ((Player.apply _).tupled, Player.unapply)
def teamFk: ForeignKeyQuery[Teams, Team] = foreignKey("team", teamId, Teams.objects)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
}
object Players {
val objects: TableQuery[Players] = TableQuery[Players]
}
开发者ID:vililahtevanoja,项目名称:Predator-App-Server,代码行数:18,代码来源:Players.scala
示例12: 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
示例13: 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
示例14: 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
示例15: TrustedKeys
//设置package包名称以及导入依赖的类
package de.m7w3.signal.store.model
import org.whispersystems.libsignal.{IdentityKey, SignalProtocolAddress}
import slick.dbio.Effect
import slick.jdbc.H2Profile
import slick.jdbc.H2Profile.api._
import slick.lifted.{ForeignKeyQuery, ProvenShape}
import slick.sql.{FixedSqlAction, FixedSqlStreamingAction}
class TrustedKeys(tag: Tag) extends Table[(Int, Array[Byte], Int)](tag, "TRUSTED_KEYS"){
def id: Rep[Int] = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def pubKey: Rep[Array[Byte]] = column[Array[Byte]]("PUB_KEY")
def addressId: Rep[Int] = column[Int]("ADDRESS_ID")
def address: ForeignKeyQuery[Addresses, Address] = foreignKey("TRUSTED_KEYS_ADDRESS_FK", addressId, Addresses.addresses)(_.id)
override def * : ProvenShape[(Int, Array[Byte], Int)] = (id, pubKey, addressId)
}
object TrustedKeys {
def exists(address: SignalProtocolAddress, identityKey: IdentityKey): FixedSqlAction[Boolean, H2Profile.api.NoStream, Effect.Read] = {
val addressId = address.hashCode()
val pubKeyBytes = identityKey.serialize()
trustedKeys.filter(trustedKey => {
trustedKey.addressId === addressId && trustedKey.pubKey === pubKeyBytes
}).exists.result
}
def get(address: SignalProtocolAddress): FixedSqlStreamingAction[Seq[((Int, Array[Byte], Int), Address)], ((Int, Array[Byte], Int), Address), Effect.Read] = {
val addressId = address.hashCode()
val join = trustedKeys join Addresses.addresses on (_.addressId === _.id)
join.filter(_._1.addressId === addressId).take(1).result
}
val trustedKeys: TableQuery[TrustedKeys] = TableQuery[TrustedKeys]
def upsert(address: SignalProtocolAddress, trustedKey: IdentityKey): FixedSqlAction[Option[Int], NoStream, Effect.Write] = {
val IGNORED = 42
val addressId = address.hashCode()
(trustedKeys returning trustedKeys.map(_.id)).insertOrUpdate((IGNORED, trustedKey.serialize(), addressId))
}
}
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:44,代码来源:TrustedKeys.scala
注:本文中的slick.lifted.ForeignKeyQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论