本文整理汇总了Scala中slick.lifted.Tag类的典型用法代码示例。如果您正苦于以下问题:Scala Tag类的具体用法?Scala Tag怎么用?Scala Tag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: User
//设置package包名称以及导入依赖的类
package models
import java.util.Date
import slick.driver.PostgresDriver.api._
import slick.lifted.Tag
case class User(
id: Option[Long],
firstName: String,
lastName: String,
fullName: String,
age: Int,
active: Boolean
)
class Users(tag: Tag) extends Table[User](tag, "user") {
implicit val dateColumnType = MappedColumnType.base[Date, Long](d => d.getTime, d => new Date(d))
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("firstName")
def lastName = column[String]("lastName")
def fullName = column[String]("fullName")
def age = column[Int]("age")
def active = column[Boolean]("active")
override def * = (id.?, firstName, lastName, fullName, age, active) <> (User.tupled, User.unapply)
}
示例2: Friend
//设置package包名称以及导入依赖的类
package net.scalax.fsn.database.test
import slick.jdbc.H2Profile.api._
import slick.lifted.Tag
case class Friend(
id: Option[Long] = None,
name: String,
nick: String,
age: Option[Int],
grade: Int
)
class FriendTable(tag: Tag) extends Table[Friend](tag, "friend") {
def id = column[Long]("id", O.AutoInc)
def name = column[String]("name")
def nick = column[String]("nick")
def age = column[Option[Int]]("age")
def grade = column[Int]("grade")
def * = (id.?, name, nick, age, grade).mapTo[Friend]
}
object FriendTable extends TableQuery(cons => new FriendTable(cons))
class SimpleTable(tag: Tag, tbName: String) extends Table[Unit](tag, tbName) {
def * = ()
}
object SimpleTable {
def tq(tbName: String): TableQuery[SimpleTable] = {
TableQuery(cons => new SimpleTable(cons, tbName))
}
}
示例3: StickerPackTable
//设置package包名称以及导入依赖的类
package im.actor.server.persist
import slick.lifted.Tag
import im.actor.server.db.ActorPostgresDriver.api._
import im.actor.server.model.StickerPack
class StickerPackTable(tag: Tag) extends Table[StickerPack](tag, "sticker_packs") {
def id = column[Int]("id", O.PrimaryKey)
def accessSalt = column[String]("access_salt")
def ownerUserId = column[Int]("owner_user_id")
def isDefault = column[Boolean]("is_default")
def * = (id, accessSalt, ownerUserId, isDefault) <> (StickerPack.tupled, StickerPack.unapply)
}
object StickerPackRepo {
val stickerPacks = TableQuery[StickerPackTable]
def create(pack: StickerPack) =
stickerPacks += pack
def setDefault(packId: Int, isDefault: Boolean): DBIO[Int] =
stickerPacks.filter(_.id === packId).map(_.isDefault).update(isDefault)
def findByOwner(userId: Int): DBIO[Seq[StickerPack]] =
stickerPacks.filter(_.ownerUserId === userId).result
def exists(userId: Int, packId: Int): DBIO[Boolean] =
stickerPacks.filter(p ? (p.id === packId) && (p.ownerUserId === userId)).exists.result
def exists(packId: Int): DBIO[Boolean] =
stickerPacks.filter(_.id === packId).exists.result
def find(id: Int) = stickerPacks.filter(_.id === id).result.headOption
def find(ids: Seq[Int], withDefault: Boolean = true): DBIO[Seq[StickerPack]] =
(if (withDefault)
stickerPacks.filter(p ? p.isDefault || (p.id inSet ids.toSet))
else
stickerPacks.filter(p ? p.id inSet ids)).result
}
示例4: Suppliers
//设置package包名称以及导入依赖的类
package chehao.myscala.slick
import slick.driver.H2Driver.api._
import slick.lifted.Tag
import slick.lifted.{ProvenShape, ForeignKeyQuery}
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)
}
示例5: Region
//设置package包名称以及导入依赖的类
package database
import scala.concurrent._
import scala.concurrent.duration._
import javax.inject.Inject
import play.api.Play
import javax.inject._
import play.api.libs.concurrent.Execution.Implicits._
import slick.lifted.Tag
import slick.driver.MySQLDriver.api._
case class Region(regionName:String, regionId:Option[Int] = None)
class Regions(tag:Tag) extends Table[Region](tag, "regions") {
def regionId = column[Int]("regionId", O.PrimaryKey, O.AutoInc)
def regionName = column[String]("regionName")
def * = (regionName, regionId.?)<>((Region.apply _).tupled, Region.unapply)
}
object Regions {
val db = Database.forConfig("h2mem1")
lazy val regionTable = TableQuery[Regions]
def regionName(regionId:Int):Option[Region] ={
val rName = Await.result(db.run(regionTable.filter(_.regionId === regionId).result), Duration.Inf)
if(rName.isEmpty) None else Some(rName.head)
}
}
示例6: Type
//设置package包名称以及导入依赖的类
package database
import scala.concurrent._
import scala.concurrent.duration._
import javax.inject.Inject
import play.api.Play
import javax.inject._
import play.api.libs.concurrent.Execution.Implicits._
import slick.lifted.Tag
import slick.driver.MySQLDriver.api._
case class Type(typeName:String, typeId:Option[Int] = None)
class Types(tag:Tag) extends Table[Type](tag, "types") {
def typeId = column[Int]("typeId", O.PrimaryKey, O.AutoInc)
def typeName = column[String]("typeName")
def * = (typeName, typeId.?)<>((Type.apply _).tupled, Type.unapply)
}
object Types {
val db = Database.forConfig("h2mem1")
lazy val typeTable = TableQuery[Types]
def typeName(typeId:Int):Option[Type] ={
val tName = Await.result(db.run(typeTable.filter(_.typeId === typeId).result), Duration.Inf)
if(tName.isEmpty) None else Some(tName.head)
}
}
示例7: Job
//设置package包名称以及导入依赖的类
package database
import scala.concurrent._
import scala.concurrent.duration._
import javax.inject.Inject
import play.api.Play
import javax.inject._
import play.api.libs.concurrent.Execution.Implicits._
import slick.lifted.Tag
import slick.driver.MySQLDriver.api._
import java.sql.Date
case class Job(name: String, description:String, startDate: Date, endDate:Date,jobType:Int, region:Int, hourlyPay:Double, workingTime:Int, email:String, img:Option[String] = None, id: Option[Int] = None)
// The representation of the Table jobs in the database
class Jobs(tag: Tag) extends Table[Job](tag, "jobs") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def description = column[String]("description")
def startDate = column[Date]("startDate")
def endDate = column[Date]("endDate")
def jobType = column[Int]("jobType")
def region = column[Int]("region")
def hourlyPay = column[Double]("hourlyPay")
def workingTime = column[Int]("workingTime")
def email = column[String]("email")
def img = column[String]("img")
def typeId = foreignKey("typeId", jobType, Types.typeTable)(_.typeId)
def regionId = foreignKey("regionId", region, Regions.regionTable)(_.regionId)
def * = (name, description, startDate, endDate, jobType, region, hourlyPay, workingTime, email,img.?, id.?)<>((Job.apply _).tupled, Job.unapply)
}
object Jobs {
val db = Database.forConfig("h2mem1")
val jobTable = TableQuery[Jobs]
def filteredJobs(jobType: Int, region:Int, startDate:Date):List[Job] = {
val query = (jobType, region, startDate) match {
case (j, r, d) if(j < 0 && r >= 0) => jobTable.filter(_.region === r).filter(_.startDate <= d).filter(_.endDate >= startDate)
case (j, r, d) if( r < 0 && j >= 0) => jobTable.filter(_.jobType === j).filter(_.startDate <= d).filter(_.endDate >= startDate)
case (j, r, d) if(r < 0 && j < 0) => jobTable.filter(_.startDate <= d).filter(_.endDate >= startDate)
case (j, r, d) => jobTable.filter(_.jobType === j).filter(_.region === r).filter(_.startDate <= d).filter(_.endDate >= startDate)
}
val job = for(j <- Await.result(db.run(query.result), Duration.Inf)) yield j
job.toList
}
}
示例8: StoredObjectTable
//设置package包名称以及导入依赖的类
package com.waltsu.wdht.storage.tables
import com.waltsu.wdht.storage.models.StoredObject
import slick.driver.SQLiteDriver.api._
import slick.lifted.Tag
object StoredObjectTable {
val storedObjects = TableQuery[StoredObjectTable]
def returningStoredObjects = (storedObjects returning storedObjects.map(_.id)) into ((`object`, id) => `object`.copy(id=id))
}
class StoredObjectTable(tag: Tag) extends Table[StoredObject](tag, "objects") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def key = column[String]("key")
def value = column[String]("value")
def * = (id, key, value) <> ((StoredObject.apply _).tupled, StoredObject.unapply)
}
示例9: 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)
}
}
示例10: TaskEntity
//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron.entity
import slick.driver.MySQLDriver.simple._
import slick.lifted.Tag
case class TaskEntity(name: String,
cronExpression: String,
globalDistribution: Boolean,
recipient: String,
executionInterval: Int)
class Tasks(tag: Tag) extends Table[TaskEntity](tag, "task") {
def name = column[String]("name", O.PrimaryKey)
def cronExpression = column[String]("cron_expression")
def globalDistribution = column[Boolean]("global_distribution")
def recipient = column[String]("recipient")
def executionInterval = column[Int]("execution_interval")
override def * = (name, cronExpression, globalDistribution, recipient, executionInterval) <>(TaskEntity.tupled, TaskEntity.unapply)
}
示例11: TaskExecutionEntity
//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron.entity
import java.sql.Timestamp
import slick.driver.MySQLDriver.simple._
import slick.lifted.Tag
case class TaskExecutionEntity(id: Long,
taskName: String,
runTimestamp: Timestamp,
success: Option[Boolean])
class TaskExecutions(tag: Tag) extends Table[TaskExecutionEntity](tag, "task") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def taskName = column[String]("task_name")
def runTimestamp = column[Timestamp]("run_timestamp")
def success = column[Boolean]("success")
def task = foreignKey("fk_task_execution_task", taskName, TableQuery[Tasks])(_.name)
override def * = (id, taskName, runTimestamp, success.?) <>(TaskExecutionEntity.tupled, TaskExecutionEntity.unapply)
}
示例12: Page
//设置package包名称以及导入依赖的类
package models
import java.util.Date
import java.sql.{ Date => SqlDate }
import play.api.Play.current
import slick.lifted.Tag
import java.sql.Timestamp
import slick.driver.PostgresDriver.api._
case class Page[A](items: Seq[A], page: Int, offset: Long, total: Long) {
lazy val prev = Option(page - 1).filter(_ >= 0)
lazy val next = Option(page + 1).filter(_ => (offset + items.size) < total)
}
case class Employee(id: Option[Long], name: String, address: String, dob: Option[Date], joiningDate: Date, designation: Option[String])
class Employees(tag: Tag) extends Table[Employee](tag, "EMPLOYEE") {
implicit val dateColumnType = MappedColumnType.base[Date, Long](d => d.getTime, d => new Date(d))
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def address = column[String]("address")
def dob = column[Date]("date_of_birth")
def joiningDate = column[Date]("joining_date")
def designation = column[String]("designation")
def * = (id.?, name, address, dob.?, joiningDate, designation.?) <> (Employee.tupled, Employee.unapply _)
}
示例13: Transfers
//设置package包名称以及导入依赖的类
package com.peim.model.table
import java.time.OffsetDateTime
import com.peim.model.{Transfer, TransferStatus}
import slick.driver.H2Driver.api._
import slick.lifted.Tag
class Transfers(tag: Tag) extends Table[Transfer](tag, "transfers") {
import Transfer._
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def sourceAccountId = column[Int]("source_account_id")
def destAccountId = column[Int]("dest_account_id")
def currencyId = column[Int]("currency_id")
def sum = column[Double]("sum")
def created = column[OffsetDateTime]("created")
def status = column[TransferStatus]("status")
def * = (id, sourceAccountId, destAccountId, currencyId, sum, created, status) <> (Transfer.tupled, Transfer.unapply)
}
示例14: TicketTable
//设置package包名称以及导入依赖的类
package io.github.asepsaep.laporcrawler.model
import io.github.asepsaep.laporcrawler.modules.{ DatabaseComponent, DriverComponent }
import io.github.asepsaep.laporcrawler.repository.Repository
trait TicketComponent { this: DatabaseComponent with DriverComponent ?
import slick.lifted.Tag
import driver.api._
class TicketTable(tag: Tag) extends Table[Ticket](tag, "ticket") {
def id = column[Int]("id")
def title = column[String]("title")
def content = column[String]("content")
def user = column[String]("user")
def date = column[String]("date")
def platform = column[String]("platform")
def category = column[String]("category")
def area = column[String]("area")
def status = column[String]("status")
def dispatchedTo = column[String]("dispatched_to")
override def * = (
id,
title,
content,
user.?,
date.?,
platform.?,
category.?,
area.?,
status.?,
dispatchedTo.?
) <> ((Ticket.apply _).tupled, Ticket.unapply _)
}
object TicketRepository extends Repository[TicketTable, Int](driver, db) {
import this.driver.api._
val table = TableQuery[TicketTable]
def getId(table: TicketTable) = table.id
}
}
示例15: Scenario
//设置package包名称以及导入依赖的类
package models.db
import slick.lifted.Tag
import slick.driver.SQLiteDriver.api._
case class Scenario(id: String, body: String)
class Scenarios(tag: Tag) extends Table[Scenario](tag,"scenarios") {
def id = column[String]("id")
def body = column[String]("body")
def * = (id,body) <> (Scenario.tupled,Scenario.unapply)
}
object Scenarios {
lazy val all = TableQuery[Scenarios]
val findById = Compiled {id: Rep[String] => all.filter(_.id === id)}
def add(id: String, body: String) = all += new Scenario(id,body)
def delete(id: String) = all.filter(_.id === id).delete
}