本文整理汇总了Scala中slick.driver.JdbcProfile类的典型用法代码示例。如果您正苦于以下问题:Scala JdbcProfile类的具体用法?Scala JdbcProfile怎么用?Scala JdbcProfile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JdbcProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ClientRecord
//设置package包名称以及导入依赖的类
package services.database
import com.google.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import slick.driver.JdbcProfile
case class ClientRecord(id: Int, firstName: String, lastName: String, petId: Int)
object ClientRecord {
implicit val clientRecordFormat = Json.format[ClientRecord]
}
class ClientsRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val db = dbConfig.db
import dbConfig.driver.api._
val clients = TableQuery[ClientsTable]
class ClientsTable(tag: Tag) extends Table[ClientRecord](tag, "CLIENTS") {
def id = column[Int]("ID", O.AutoInc, O.PrimaryKey)
def firstName = column[String]("FIRST_NAME")
def lastName = column[String]("LAST_NAME")
def petId = column[Int]("PET_ID")
def * = (id, firstName, lastName, petId) <> ((ClientRecord.apply _).tupled, ClientRecord.unapply)
}
}
示例2: PetRecord
//设置package包名称以及导入依赖的类
package services.database
import com.google.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import slick.driver.JdbcProfile
case class PetRecord(id: Int, name: String, notes: String)
object PetRecord {
implicit val petRecordFormat = Json.format[PetRecord]
}
class PetsRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val db = dbConfig.db
import dbConfig.driver.api._
val pets = TableQuery[PetsTable]
class PetsTable(tag: Tag) extends Table[PetRecord](tag, "PETS") {
def id = column[Int]("ID", O.AutoInc, O.PrimaryKey)
def name = column[String]("NAME")
def notes = column[String]("NOTES")
def * = (id, name, notes) <> ((PetRecord.apply _).tupled, PetRecord.unapply)
}
}
示例3: ItemRecord
//设置package包名称以及导入依赖的类
package services.database
import com.google.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import slick.driver.JdbcProfile
case class ItemRecord(id: Int, firstName: String, lastName: String, petId: Int)
object ItemRecord {
implicit val itemRecordFormat = Json.format[ItemRecord]
}
class ItemsRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val db = dbConfig.db
import dbConfig.driver.api._
val items = TableQuery[ItemsTable]
class ItemsTable(tag: Tag) extends Table[ItemRecord](tag, "ITEMS") {
def id = column[Int]("ID", O.AutoInc, O.PrimaryKey)
def firstName = column[String]("FIRST_NAME")
def lastName = column[String]("LAST_NAME")
def petId = column[Int]("PET_ID")
def * = (id, firstName, lastName, petId) <> ((ItemRecord.apply _).tupled, ItemRecord.unapply)
}
}
示例4: AccountDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import java.sql.Date
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.Account
import scala.concurrent.Future
class AccountDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class AccountTable(tag: Tag) extends Table[Account] (tag, "Account"){
def account_id = column[Long]("account_id", O.PrimaryKey, O.AutoInc)
def user_id = column[Option[Long]]("user_id")
def name = column[String]("name")
def amount = column[Long]("amount")
def category_id = column[Long]("category_id")
def register_at = column[Date]("register_at")
def payment_source_id = column[Option[Long]]("payment_source_id")
def payment_destination_id = column[Option[Long]]("payment_destination_id")
override def * = (
account_id,
user_id,
name,
amount,
category_id,
register_at,
payment_source_id,
payment_destination_id) <> (Account.tupled, Account.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val accounts = TableQuery[AccountTable]
def list: Future[Seq[Account]] = {
dbConfig.db.run(accounts.result)
}
}
示例5: PaymentDestinationDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.PaymentDestination
import scala.concurrent.Future
class PaymentDestinationDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class PaymentDestinationTable(tag: Tag) extends Table[PaymentDestination] (tag, "PaymentDestination"){
def payment_destination_id = column[Long]("payment_destination_id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def user_id = column[Option[Long]]("user_id")
override def * = (
payment_destination_id,
name,
user_id) <> (PaymentDestination.tupled, PaymentDestination.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val paymentDestination = TableQuery[PaymentDestinationTable]
def list: Future[Seq[PaymentDestination]] = {
dbConfig.db.run(paymentDestination.result)
}
}
示例6: CategoryDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.Category
import scala.concurrent.Future
class CategoryDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class CategoryTable(tag: Tag) extends Table[Category] (tag, "Category"){
def category_id = column[Long]("category_id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def hierarchy = column[Long]("hierarchy")
def user_id = column[Option[Long]]("user_id")
def parent_id = column[Option[Long]]("parent_id")
override def * = (
category_id,
name,
hierarchy,
user_id,
parent_id) <> (Category.tupled, Category.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val category = TableQuery[CategoryTable]
def list: Future[Seq[Category]] = {
dbConfig.db.run(category.result)
}
}
示例7: PaymentSourceDAO
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import models.PaymentSource
import scala.concurrent.Future
class PaymentSourceDAO @Inject() (protected val databaseConfigProvider: DatabaseConfigProvider){
private class PaymentSourceTable(tag: Tag) extends Table[PaymentSource] (tag, "PaymentSource"){
def payment_source_id = column[Long]("payment_source_id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def user_id = column[Option[Long]]("user_id")
def amount = column[Long]("amount")
override def * = (
payment_source_id,
name,
user_id,
amount) <> (PaymentSource.tupled, PaymentSource.unapply)
}
val dbConfig = databaseConfigProvider.get[JdbcProfile]
private val paymentSource = TableQuery[PaymentSourceTable]
def list: Future[Seq[PaymentSource]] = {
dbConfig.db.run(paymentSource.result)
}
}
示例8: SolarInfoStorage
//设置package包名称以及导入依赖的类
package storages
import java.time.LocalDateTime
import java.util.UUID
import javax.inject.Inject
import models.SolarInfo
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import support.database.PvPostgresDriver.api._
import scala.concurrent.{ExecutionContext, Future}
class SolarInfoStorage(tag: Tag) extends Table[SolarInfo](tag, "solar_info") {
def id = column[UUID]("id", O.PrimaryKey)
def monitoring_time = column[LocalDateTime]("monitoring_time")
def irradiance = column[Double]("irradiance")
def panel_temp = column[Double]("panel_temp")
def ambient_temp = column[Double]("ambient_temp")
def wind_speed = column[Double]("wind_speed")
def wind_dir = column[Double]("wind_dir")
def sum_energy = column[Double]("sum_energy")
override def * = (id, monitoring_time, irradiance, panel_temp, ambient_temp, wind_speed, wind_dir, sum_energy) <> (SolarInfo.tupled, SolarInfo.unapply)
}
object SolarInfoStorage {
val tableQuery = TableQuery[SolarInfoStorage]
}
class SolarInfoRepository @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) {
val dbconfig = dbConfigProvider.get[JdbcProfile]
val db = dbconfig.db
private val SolarInfos = SolarInfoStorage.tableQuery
def findById(id: UUID): Future[SolarInfo] = db.run(SolarInfos.filter(_.id === id).result.head)
def all(): Future[List[SolarInfo]] = db.run(SolarInfos.to[List].result)
def create(solarInfo: SolarInfo): Future[UUID] = db.run(SolarInfos returning SolarInfos.map(_.id) += solarInfo)
def delete(id: UUID): Future[Boolean] = db.run(SolarInfos.filter(_.id === id).delete).map(_ > 0)
}
示例9: LanguageTable
//设置package包名称以及导入依赖的类
package repository
import com.google.inject.Inject
import com.google.inject.ImplementedBy
import models.Language
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.Future
trait LanguageTable extends UserTable{ self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class LanguageTable(tag:Tag) extends Table[Language](tag,"language") {
val id=column[Int]("id")
val name= column[String]("name", O.SqlType("VARCHAR(200)"))
val fluency=column[String]("fluency", O.SqlType("VARCHAR(200)"))
def * = (id, name,fluency) <>(Language.tupled, Language.unapply)
}
val languageTableQuery = TableQuery[LanguageTable]
}
//@ImplementedBy(classOf[LanguageImpl])
class LanguageRepo @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends LanguageTable with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
def insert(id: Int, name: String, fluency: String): Future[Int] = {
val insertQuery=languageTableQuery += Language(id, name, fluency)
db.run {insertQuery}
}
def update(id: Int, name: String, fluency: String): Future[Int] = db.run {languageTableQuery.filter(_.id === id).update(Language(id, name, fluency))}
def delete(name:String): Future[Int] = db.run { languageTableQuery.filter(_.name === name).delete}
def getAll(): Future[List[Language]] = db.run {
val test=languageTableQuery.to[List]
test.result
}
def getLanguage(id:Int): Future[Seq[Language]] = {
db.run(languageTableQuery.filter(_.id === id).result)
}
}
示例10: Restaurants
//设置package包名称以及导入依赖的类
package dao;
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import play.api.Play
import slick.driver.PostgresDriver.api._
import scala.concurrent.Future
import model.CompleteRestaurant
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import play.api.Play
import slick.driver.PostgresDriver.api._
import scala.concurrent.Future
import model.CompleteRestaurant
import scala.concurrent.ExecutionContext.Implicits.global
import model.RestaurantTableDef
object Restaurants {
val dbConfig=DatabaseConfigProvider.get[JdbcProfile](Play.current)
val restaurants=TableQuery[RestaurantTableDef]
def list:Future[Seq[CompleteRestaurant]]={
dbConfig.db.run(restaurants.result)
}
def getById(id:Long): Future[Option[CompleteRestaurant]]={
dbConfig.db.run(restaurants.filter(_.id===id).result.headOption)
}
def save(restaurant:CompleteRestaurant):Future[String]={
dbConfig.db.run(restaurants+=restaurant).map(res => "Restaurant saved").recover{
case ex: Exception => ex.getCause.getMessage
}
}
def update(restaurant:CompleteRestaurant):Future[Int]={
dbConfig.db.run(restaurants.filter(_.id===restaurant.id).update(restaurant))
}
def delete(id:Long):Future[Int]={
dbConfig.db.run(restaurants.filter(_.id===id).delete)
}
}
示例11: Campaign
//设置package包名称以及导入依赖的类
package models
import play.api.Play
import slick.driver.H2Driver.api._
import scala.concurrent.Future
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import slick.driver.JdbcProfile
case class Campaign(id: Option[Int], title: String, content: String)
trait CampaignsTable {
class Campaigns(tag: Tag) extends Table[Campaign](tag, "CAMPAIGNS") {
def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
def title = column[String]("TITLE")
def content = column[String]("CONTENT")
def * = (id.?, title, content) <> (Campaign.tupled, Campaign.unapply)
}
val campaigns = TableQuery[Campaigns]
}
object CampaignsDAO extends HasDatabaseConfig[JdbcProfile] with CampaignsTable {
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
def findById(id: Int): Future[Option[Campaign]] =
db.run(campaigns.filter(_.id === id).result.headOption)
def findAll: Future[Seq[Campaign]] =
db.run(campaigns.result)
def insert(newRecord: Campaign): Future[Int] = {
db.run((campaigns returning campaigns.map(_.id)) += newRecord)
}
def update(record: Campaign): Future[Int] = {
db.run(campaigns.filter(_.id === record.id)
.map(a => (a.title, a.content))
.update((record.title, record.content)))
}
def getCampaignIds: Future[Seq[Int]] = {
db.run(campaigns.map(row => (row.id)).result)
}
}
示例12: PhraseDao
//设置package包名称以及导入依赖的类
package daos
import java.sql.Timestamp
import java.util.Date
import javax.inject.Inject
import models.Phrase
import org.joda.time.DateTime
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import slick.driver.JdbcProfile
import scala.concurrent.Future
class PhraseDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
private val Phrases = TableQuery[PhrasesTable]
def all(): Future[Seq[Phrase]] = db.run(Phrases.result)
def insert(phrase: Phrase): Future[Unit] = db.run(Phrases += phrase).map { _ => () }
def insert(phrases: Seq[Phrase]): Future[Unit] = db.run(this.Phrases ++= phrases).map(_ => ())
def findById(id: Long): Future[Option[Phrase]] = db.run(Phrases.filter(_.id === id).result.headOption)
def update(id: Long, phrase: Phrase): Future[Unit] = {
val phraseToUpdate: Phrase = phrase.copy(Some(id))
db.run(Phrases.filter(_.id === id).update(phraseToUpdate)).map(_ => ())
}
def delete(id: Long): Future[Unit] =
db.run(Phrases.filter(_.id === id).delete).map(_ => ())
def count(): Future[Int] = {
// this should be changed to db.run(Phrases.length.result) when https://github.com/slick/slick/issues/1237 is fixed
db.run(Phrases.map(_.id).length.result)
}
private class PhrasesTable(tag: Tag) extends Table[Phrase](tag, "PHRASE") {
//implicit val dateColumnType = MappedColumnType.base[Date, Long](d => d.getTime, d => new Date(d))
implicit def dateTime = MappedColumnType.base[DateTime, Timestamp] (
dt => new Timestamp(dt.getMillis), ts => new DateTime(ts.getTime)
)
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def spanish = column[String]("SPANISH")
def english = column[String]("ENGLISH")
def createdAt = column[DateTime]("CREATED_AT")
def * = (id.?, spanish, english, createdAt) <> (Phrase.tupled, Phrase.unapply _)
}
}
示例13: PersonDAOImpl
//设置package包名称以及导入依赖的类
package dao
import javax.inject.Inject
import javax.inject.Singleton
import scala.concurrent.Future
import play.api.Configuration
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.db.NamedDatabase
import models.Person
import slick.driver.JdbcProfile
@Singleton
class PersonDAOImpl @Inject() (@NamedDatabase("mydb") protected val dbConfigProvider: DatabaseConfigProvider, conf: Configuration) extends PersonDAO with HasDatabaseConfigProvider[JdbcProfile] with Tables {
import driver.api._
val loadedDb = conf.getString("slick.dbs.mydb.db.url")//just for demo, should be "blah" in PersonDAOImplSpec
println("LOADED CONFIG FOR DB: " + loadedDb)
def findAll(): Future[Seq[Person]] =
db.run(persons.result).map { res => println("Hello from real DAO!"); res }
def insert(p: Person): Future[Int] =
db.run(persons += p)
def createTables(): Future[Unit] =
db.run(persons.schema.create)
}
trait Tables { self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class PersonsTable(tag: Tag) extends Table[Person](tag, "PERSON") {
def id = column[Int]("ID", O.PrimaryKey)
def name = column[String]("NAME")
def age = column[Int]("AGE")
def * = (id, name, age) <> (Person.tupled, Person.unapply _)
}
lazy val persons = TableQuery[PersonsTable]
}
示例14: Restaurante
//设置package包名称以及导入依赖的类
package models
import javax.inject._
import play.api.Application
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import play.api.db.slick.DatabaseConfigProvider
import slick.backend.DatabaseConfig
import scala.concurrent.Future
case class Restaurante (var id:Int,var nombre:String,var direccion:String)
class RestauranteTableDef(tag: Tag) extends Table[Restaurante](tag, "Restaurantes") {
def id = column[Int]("id", O.PrimaryKey,O.AutoInc)
def nombre = column[String]("Nombre")
def direccion = column[String]("Direccion")
override def * =
(id, nombre, direccion) <>(Restaurante.tupled, Restaurante.unapply)
}
class Restaurantes @Inject() (appProvider: Provider[Application]) {
def dbConfig(): DatabaseConfig[JdbcProfile] =
DatabaseConfigProvider.get[JdbcProfile](appProvider.get())
val restaurantes = TableQuery[RestauranteTableDef]
var lista :List[Restaurante]={
List(
Restaurante(
3
,"La casa blanca"
,"Argentina"
),
Restaurante(
4
,"La casa rosta"
,"Manizales"
)
)
}
def adicionar(restaurante: Restaurante)={
lista = lista ::: List(restaurante)
}
def traerTodo:Future[Seq[Restaurante]]={
dbConfig().db.run(restaurantes.result)
}
}
示例15: TenantDaoImpl
//设置package包名称以及导入依赖的类
package dao
import com.google.inject.{Inject, Singleton}
import models.Tenant
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.Future
@Singleton
class TenantDaoImpl @Inject()(databaseConfigProvider: DatabaseConfigProvider) extends TenantDao {
val dbConfig = databaseConfigProvider.get[JdbcProfile]
import dbConfig._
import driver.api._
class TenantTable(tag : Tag) extends Table[Tenant](tag, "tenants") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("first_name")
def lastName = column[String]("last_name")
def mobile = column[Long]("mobile")
def email = column[String]("email")
override def * =
(id, firstName, lastName, mobile, email) <> (Tenant.tupled, Tenant.unapply)
}
implicit val tenants = TableQuery[TenantTable]
override def add(tenant: Tenant): Future[String] = {
db.run(tenants += tenant).map(res => "Tenant Successfully Added").recover {
case ex : Exception => ex.getCause.getMessage
}
}
override def get(id: Long): Future[Option[Tenant]] = {
db.run(tenants.filter(_.id === id).result.headOption)
}
override def delete(id: Long): Future[Int] = {
db.run(tenants.filter(_.id === id).delete)
}
override def listAll: Future[Seq[Tenant]] = {
db.run(tenants.result)
}
}