Advertisement
Guest User

Untitled

a guest
Apr 6th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 8.21 KB | None | 0 0
  1. package Models
  2. // AUTO-GENERATED Slick data model
  3. /** Stand-alone Slick data model for immediate use */
  4. object Tables extends {
  5.   val profile = slick.driver.MySQLDriver
  6. } with Tables
  7.  
  8. /** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */
  9. trait Tables {
  10.   val profile: slick.driver.JdbcProfile
  11.   import profile.api._
  12.   import slick.model.ForeignKeyAction
  13.   // NOTE: GetResult mappers for plain SQL are only generated for tables where Slick knows how to map the types of all columns.
  14.   import slick.jdbc.{GetResult => GR}
  15.  
  16.   /** DDL for all tables. Call .create to execute. */
  17.   lazy val schema: profile.SchemaDescription = Address.schema ++ Customer.schema ++ CustomerAddress.schema ++ Images.schema
  18.   @deprecated("Use .schema instead of .ddl", "3.0")
  19.   def ddl = schema
  20.  
  21.   /** Entity class storing rows of table Address
  22.     *  @param id Database column id SqlType(INT), AutoInc, PrimaryKey
  23.     *  @param street Database column street SqlType(VARCHAR), Length(128,true)
  24.     *  @param city Database column city SqlType(VARCHAR), Length(128,true)
  25.     *  @param zipcode Database column zipcode SqlType(VARCHAR), Length(10,true) */
  26.   case class AddressRow(id: Int, street: String, city: String, zipcode: String)
  27.   /** GetResult implicit for fetching AddressRow objects using plain SQL queries */
  28.   implicit def GetResultAddressRow(implicit e0: GR[Int], e1: GR[String]): GR[AddressRow] = GR{
  29.     prs => import prs._
  30.       AddressRow.tupled((<<[Int], <<[String], <<[String], <<[String]))
  31.   }
  32.   /** Table description of table address. Objects of this class serve as prototypes for rows in queries. */
  33.   class Address(_tableTag: Tag) extends Table[AddressRow](_tableTag, "address") {
  34.     def * = (id, street, city, zipcode) <> (AddressRow.tupled, AddressRow.unapply)
  35.     /** Maps whole row to an option. Useful for outer joins. */
  36.     def ? = (Rep.Some(id), Rep.Some(street), Rep.Some(city), Rep.Some(zipcode)).shaped.<>({r=>import r._; _1.map(_=> AddressRow.tupled((_1.get, _2.get, _3.get, _4.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
  37.  
  38.     /** Database column id SqlType(INT), AutoInc, PrimaryKey */
  39.     val id: Rep[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
  40.     /** Database column street SqlType(VARCHAR), Length(128,true) */
  41.     val street: Rep[String] = column[String]("street", O.Length(128,varying=true))
  42.     /** Database column city SqlType(VARCHAR), Length(128,true) */
  43.     val city: Rep[String] = column[String]("city", O.Length(128,varying=true))
  44.     /** Database column zipcode SqlType(VARCHAR), Length(10,true) */
  45.     val zipcode: Rep[String] = column[String]("zipcode", O.Length(10,varying=true))
  46.   }
  47.   /** Collection-like TableQuery object for table Address */
  48.   lazy val Address = new TableQuery(tag => new Address(tag))
  49.  
  50.   /** Entity class storing rows of table Customer
  51.     *  @param id Database column id SqlType(INT), AutoInc, PrimaryKey
  52.     *  @param name Database column name SqlType(VARCHAR), Length(255,true)
  53.     *  @param imageId Database column image_id SqlType(INT), Default(None) */
  54.   case class CustomerRow(id: Int, name: String, imageId: Option[Int] = None)
  55.   /** GetResult implicit for fetching CustomerRow objects using plain SQL queries */
  56.   implicit def GetResultCustomerRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[Int]]): GR[CustomerRow] = GR{
  57.     prs => import prs._
  58.       CustomerRow.tupled((<<[Int], <<[String], <<?[Int]))
  59.   }
  60.   /** Table description of table customer. Objects of this class serve as prototypes for rows in queries. */
  61.   class Customer(_tableTag: Tag) extends Table[CustomerRow](_tableTag, "customer") {
  62.     def * = (id, name, imageId) <> (CustomerRow.tupled, CustomerRow.unapply)
  63.     /** Maps whole row to an option. Useful for outer joins. */
  64.     def ? = (Rep.Some(id), Rep.Some(name), imageId).shaped.<>({r=>import r._; _1.map(_=> CustomerRow.tupled((_1.get, _2.get, _3)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
  65.  
  66.     /** Database column id SqlType(INT), AutoInc, PrimaryKey */
  67.     val id: Rep[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
  68.     /** Database column name SqlType(VARCHAR), Length(255,true) */
  69.     val name: Rep[String] = column[String]("name", O.Length(255,varying=true))
  70.     /** Database column image_id SqlType(INT), Default(None) */
  71.     val imageId: Rep[Option[Int]] = column[Option[Int]]("image_id", O.Default(None))
  72.  
  73.     /** Foreign key referencing Images (database name imagekey) */
  74.     lazy val imagesFk = foreignKey("imagekey", imageId, Images)(r => Rep.Some(r.id), onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  75.   }
  76.   /** Collection-like TableQuery object for table Customer */
  77.   lazy val Customer = new TableQuery(tag => new Customer(tag))
  78.  
  79.   /** Entity class storing rows of table CustomerAddress
  80.     *  @param customerId Database column customer_id SqlType(INT)
  81.     *  @param addressId Database column address_id SqlType(INT) */
  82.   case class CustomerAddressRow(customerId: Int, addressId: Int)
  83.   /** GetResult implicit for fetching CustomerAddressRow objects using plain SQL queries */
  84.   implicit def GetResultCustomerAddressRow(implicit e0: GR[Int]): GR[CustomerAddressRow] = GR{
  85.     prs => import prs._
  86.       CustomerAddressRow.tupled((<<[Int], <<[Int]))
  87.   }
  88.   /** Table description of table customer_address. Objects of this class serve as prototypes for rows in queries. */
  89.   class CustomerAddress(_tableTag: Tag) extends Table[CustomerAddressRow](_tableTag, "customer_address") {
  90.     def * = (customerId, addressId) <> (CustomerAddressRow.tupled, CustomerAddressRow.unapply)
  91.     /** Maps whole row to an option. Useful for outer joins. */
  92.     def ? = (Rep.Some(customerId), Rep.Some(addressId)).shaped.<>({r=>import r._; _1.map(_=> CustomerAddressRow.tupled((_1.get, _2.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
  93.  
  94.     /** Database column customer_id SqlType(INT) */
  95.     val customerId: Rep[Int] = column[Int]("customer_id")
  96.     /** Database column address_id SqlType(INT) */
  97.     val addressId: Rep[Int] = column[Int]("address_id")
  98.  
  99.     /** Primary key of CustomerAddress (database name customer_address_PK) */
  100.     val pk = primaryKey("customer_address_PK", (customerId, addressId))
  101.  
  102.     /** Foreign key referencing Address (database name address) */
  103.     lazy val addressFk = foreignKey("address", addressId, Address)(r => r.id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  104.     /** Foreign key referencing Customer (database name customer) */
  105.     lazy val customerFk = foreignKey("customer", customerId, Customer)(r => r.id, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  106.   }
  107.   /** Collection-like TableQuery object for table CustomerAddress */
  108.   lazy val CustomerAddress = new TableQuery(tag => new CustomerAddress(tag))
  109.  
  110.   /** Entity class storing rows of table Images
  111.     *  @param id Database column id SqlType(INT), PrimaryKey
  112.     *  @param image Database column image SqlType(MEDIUMBLOB) */
  113.   case class ImagesRow(id: Int, image: java.sql.Blob)
  114.   /** GetResult implicit for fetching ImagesRow objects using plain SQL queries */
  115.   implicit def GetResultImagesRow(implicit e0: GR[Int], e1: GR[java.sql.Blob]): GR[ImagesRow] = GR{
  116.     prs => import prs._
  117.       ImagesRow.tupled((<<[Int], <<[java.sql.Blob]))
  118.   }
  119.   /** Table description of table images. Objects of this class serve as prototypes for rows in queries. */
  120.   class Images(_tableTag: Tag) extends Table[ImagesRow](_tableTag, "images") {
  121.     def * = (id, image) <> (ImagesRow.tupled, ImagesRow.unapply)
  122.     /** Maps whole row to an option. Useful for outer joins. */
  123.     def ? = (Rep.Some(id), Rep.Some(image)).shaped.<>({r=>import r._; _1.map(_=> ImagesRow.tupled((_1.get, _2.get)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))
  124.  
  125.     /** Database column id SqlType(INT), PrimaryKey */
  126.     val id: Rep[Int] = column[Int]("id", O.PrimaryKey)
  127.     /** Database column image SqlType(MEDIUMBLOB) */
  128.     val image: Rep[java.sql.Blob] = column[java.sql.Blob]("image")
  129.   }
  130.   /** Collection-like TableQuery object for table Images */
  131.   lazy val Images = new TableQuery(tag => new Images(tag))
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement