Slick 编程(2): 准备开发环境

jerry Scala 2015年11月25日 收藏

本篇介绍如果设置使用Slick的Scala开发环境,这里我们使用SBT命令行,SBT使用的目录结构和Maven一样,我们可以创建一个目录,比如Slick,然后创建如下的缺省目录结构:

src
   main
      java
      resources
      scala
   test
   java
   resources
   scala

因为我们打算使用MySQL数据库,并使用Slick来访问数据库,因此我们在Slick的根目录下创建一个build.sbt,添加相关引用:

  1. name := "Scala Slick Examples"
  2.  
  3. version := "1.0"
  4.  
  5. scalaVersion := "2.10.4"
  6.  
  7. libraryDependencies += "com.typesafe.slick" %% "slick" % "2.0.2"
  8.  
  9. libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.6.4"
  10.  
  11. libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.18"
  12.  

Slick使用SLF4J 作为日志库文件。
我们的MySQL数据库 Chinook 安装在本地服务器上面,我们在使用Slick可以手工创建数据库表Schema的定义,也可以使用自动代码生成工具从已有的数据库创建Table的Schema定义。
我们在命令行输入 sbt ,进入SBT控制台。
然后我们使用console,进入Scala控制台,注意此时SBT自动把build.sbt中引用到的库比如slick, mysql添加到Scala控制台,我们使用如下命令:

  1. scala.slick.model.codegen.SourceCodeGenerator.main(
  2. Array(slickDriver, jdbcDriver, url, outputFolder, pkg, user, password)
  3. )

相关参数如下:
slickDriver Fully qualified name of Slick driver class, e.g. “scala.slick.driver.H2Driver”
jdbcDriver Fully qualified name of jdbc driver class, e.g. “org.h2.Driver”
url jdbc url, e.g. “jdbc:postgresql://localhost/test”
outputFolder Place where the package folder structure should be put
pkg Scala package the generated code should be places in
user database connection user name
password database connection password

例如对于,我们使用mysql数据库,可以在命令行输入如下命令:注意修改你的用户名和密码:

  1. scala.slick.model.codegen.SourceCodeGenerator.main(
  2. Array("scala.slick.driver.MySQLDriver", "com.mysql.jdbc.Driver",
  3. "jdbc:mysql://127.0.0.1/Chinook",
  4. "./src/main/scala",
  5. "com.guidebee.slick.example", "user", "password")
  6. )

这样自动代码生成工具,就在/src/main/scala目录下生成了Tables.scala文件

  1. package com.guidebee.slick.example
  2. // AUTO-GENERATED Slick data model
  3. /** Stand-alone Slick data model for immediate use */
  4. object Tables extends {
  5. val profile = scala.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: scala.slick.driver.JdbcProfile
  11. import profile.simple._
  12. import scala.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 scala.slick.jdbc.{GetResult => GR}
  15. /** DDL for all tables. Call .create to execute. */
  16. lazy val ddl = Album.ddl ++ Artist.ddl ++ Customer.ddl ++ Employee.ddl ++ Genre.ddl ++ Invoice.ddl ++ Invoiceline.ddl ++ Mediatype.ddl ++ Playlist.ddl ++ Playlisttrack.ddl ++ Track.ddl
  17. /** Entity class storing rows of table Album
  18. * @param albumid Database column AlbumId PrimaryKey
  19. * @param title Database column Title
  20. * @param artistid Database column ArtistId */
  21. case class AlbumRow(albumid: Int, title: String, artistid: Int)
  22. /** GetResult implicit for fetching AlbumRow objects using plain SQL queries */
  23. implicit def GetResultAlbumRow(implicit e0: GR[Int], e1: GR[String]): GR[AlbumRow] = GR{
  24. prs => import prs._
  25. AlbumRow.tupled((<<[Int], <<[String], <<[Int]))
  26. }
  27. /** Table description of table Album. Objects of this class serve as prototypes for rows in queries. */
  28. class Album(tag: Tag) extends Table[AlbumRow](tag, "Album") {
  29. def * = (albumid, title, artistid) <> (AlbumRow.tupled, AlbumRow.unapply)
  30. /** Maps whole row to an option. Useful for outer joins. */
  31. def ? = (albumid.?, title.?, artistid.?).shaped.<>({r=>import r._; _1.map(_=> AlbumRow.tupled((_1.get, _2.get, _3.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  32. /** Database column AlbumId PrimaryKey */
  33. val albumid: Column[Int] = column[Int]("AlbumId", O.PrimaryKey)
  34. /** Database column Title */
  35. val title: Column[String] = column[String]("Title")
  36. /** Database column ArtistId */
  37. val artistid: Column[Int] = column[Int]("ArtistId")
  38. /** Foreign key referencing Artist (database name FK_AlbumArtistId) */
  39. lazy val artistFk = foreignKey("FK_AlbumArtistId", artistid, Artist)(r => r.artistid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  40. }
  41. /** Collection-like TableQuery object for table Album */
  42. lazy val Album = new TableQuery(tag => new Album(tag))
  43. /** Entity class storing rows of table Artist
  44. * @param artistid Database column ArtistId PrimaryKey
  45. * @param name Database column Name */
  46. case class ArtistRow(artistid: Int, name: Option[String])
  47. /** GetResult implicit for fetching ArtistRow objects using plain SQL queries */
  48. implicit def GetResultArtistRow(implicit e0: GR[Int], e1: GR[Option[String]]): GR[ArtistRow] = GR{
  49. prs => import prs._
  50. ArtistRow.tupled((<<[Int], <<?[String]))
  51. }
  52. /** Table description of table Artist. Objects of this class serve as prototypes for rows in queries. */
  53. class Artist(tag: Tag) extends Table[ArtistRow](tag, "Artist") {
  54. def * = (artistid, name) <> (ArtistRow.tupled, ArtistRow.unapply)
  55. /** Maps whole row to an option. Useful for outer joins. */
  56. def ? = (artistid.?, name).shaped.<>({r=>import r._; _1.map(_=> ArtistRow.tupled((_1.get, _2)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  57. /** Database column ArtistId PrimaryKey */
  58. val artistid: Column[Int] = column[Int]("ArtistId", O.PrimaryKey)
  59. /** Database column Name */
  60. val name: Column[Option[String]] = column[Option[String]]("Name")
  61. }
  62. /** Collection-like TableQuery object for table Artist */
  63. lazy val Artist = new TableQuery(tag => new Artist(tag))
  64. /** Entity class storing rows of table Customer
  65. * @param customerid Database column CustomerId PrimaryKey
  66. * @param firstname Database column FirstName
  67. * @param lastname Database column LastName
  68. * @param company Database column Company
  69. * @param address Database column Address
  70. * @param city Database column City
  71. * @param state Database column State
  72. * @param country Database column Country
  73. * @param postalcode Database column PostalCode
  74. * @param phone Database column Phone
  75. * @param fax Database column Fax
  76. * @param email Database column Email
  77. * @param supportrepid Database column SupportRepId */
  78. case class CustomerRow(customerid: Int, firstname: String, lastname: String, company: Option[String], address: Option[String], city: Option[String], state: Option[String], country: Option[String], postalcode: Option[String], phone: Option[String], fax: Option[String], email: String, supportrepid: Option[Int])
  79. /** GetResult implicit for fetching CustomerRow objects using plain SQL queries */
  80. implicit def GetResultCustomerRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[String]], e3: GR[Option[Int]]): GR[CustomerRow] = GR{
  81. prs => import prs._
  82. CustomerRow.tupled((<<[Int], <<[String], <<[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<[String], <<?[Int]))
  83. }
  84. /** Table description of table Customer. Objects of this class serve as prototypes for rows in queries. */
  85. class Customer(tag: Tag) extends Table[CustomerRow](tag, "Customer") {
  86. def * = (customerid, firstname, lastname, company, address, city, state, country, postalcode, phone, fax, email, supportrepid) <> (CustomerRow.tupled, CustomerRow.unapply)
  87. /** Maps whole row to an option. Useful for outer joins. */
  88. def ? = (customerid.?, firstname.?, lastname.?, company, address, city, state, country, postalcode, phone, fax, email.?, supportrepid).shaped.<>({r=>import r._; _1.map(_=> CustomerRow.tupled((_1.get, _2.get, _3.get, _4, _5, _6, _7, _8, _9, _10, _11, _12.get, _13)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  89. /** Database column CustomerId PrimaryKey */
  90. val customerid: Column[Int] = column[Int]("CustomerId", O.PrimaryKey)
  91. /** Database column FirstName */
  92. val firstname: Column[String] = column[String]("FirstName")
  93. /** Database column LastName */
  94. val lastname: Column[String] = column[String]("LastName")
  95. /** Database column Company */
  96. val company: Column[Option[String]] = column[Option[String]]("Company")
  97. /** Database column Address */
  98. val address: Column[Option[String]] = column[Option[String]]("Address")
  99. /** Database column City */
  100. val city: Column[Option[String]] = column[Option[String]]("City")
  101. /** Database column State */
  102. val state: Column[Option[String]] = column[Option[String]]("State")
  103. /** Database column Country */
  104. val country: Column[Option[String]] = column[Option[String]]("Country")
  105. /** Database column PostalCode */
  106. val postalcode: Column[Option[String]] = column[Option[String]]("PostalCode")
  107. /** Database column Phone */
  108. val phone: Column[Option[String]] = column[Option[String]]("Phone")
  109. /** Database column Fax */
  110. val fax: Column[Option[String]] = column[Option[String]]("Fax")
  111. /** Database column Email */
  112. val email: Column[String] = column[String]("Email")
  113. /** Database column SupportRepId */
  114. val supportrepid: Column[Option[Int]] = column[Option[Int]]("SupportRepId")
  115. /** Foreign key referencing Employee (database name FK_CustomerSupportRepId) */
  116. lazy val employeeFk = foreignKey("FK_CustomerSupportRepId", supportrepid, Employee)(r => r.employeeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  117. }
  118. /** Collection-like TableQuery object for table Customer */
  119. lazy val Customer = new TableQuery(tag => new Customer(tag))
  120. /** Entity class storing rows of table Employee
  121. * @param employeeid Database column EmployeeId PrimaryKey
  122. * @param lastname Database column LastName
  123. * @param firstname Database column FirstName
  124. * @param title Database column Title
  125. * @param reportsto Database column ReportsTo
  126. * @param birthdate Database column BirthDate
  127. * @param hiredate Database column HireDate
  128. * @param address Database column Address
  129. * @param city Database column City
  130. * @param state Database column State
  131. * @param country Database column Country
  132. * @param postalcode Database column PostalCode
  133. * @param phone Database column Phone
  134. * @param fax Database column Fax
  135. * @param email Database column Email */
  136. case class EmployeeRow(employeeid: Int, lastname: String, firstname: String, title: Option[String], reportsto: Option[Int], birthdate: Option1, hiredate: Option1, address: Option[String], city: Option[String], state: Option[String], country: Option[String], postalcode: Option[String], phone: Option[String], fax: Option[String], email: Option[String])
  137. /** GetResult implicit for fetching EmployeeRow objects using plain SQL queries */
  138. implicit def GetResultEmployeeRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[String]], e3: GR[Option[Int]], e4: GR[Option1]): GR[EmployeeRow] = GR{
  139. prs => import prs._
  140. EmployeeRow.tupled((<<[Int], <<[String], <<[String], <<?[String], <<?[Int], <<?1, <<?1, <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<?[String]))
  141. }
  142. /** Table description of table Employee. Objects of this class serve as prototypes for rows in queries. */
  143. class Employee(tag: Tag) extends Table[EmployeeRow](tag, "Employee") {
  144. def * = (employeeid, lastname, firstname, title, reportsto, birthdate, hiredate, address, city, state, country, postalcode, phone, fax, email) <> (EmployeeRow.tupled, EmployeeRow.unapply)
  145. /** Maps whole row to an option. Useful for outer joins. */
  146. def ? = (employeeid.?, lastname.?, firstname.?, title, reportsto, birthdate, hiredate, address, city, state, country, postalcode, phone, fax, email).shaped.<>({r=>import r._; _1.map(_=> EmployeeRow.tupled((_1.get, _2.get, _3.get, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  147. /** Database column EmployeeId PrimaryKey */
  148. val employeeid: Column[Int] = column[Int]("EmployeeId", O.PrimaryKey)
  149. /** Database column LastName */
  150. val lastname: Column[String] = column[String]("LastName")
  151. /** Database column FirstName */
  152. val firstname: Column[String] = column[String]("FirstName")
  153. /** Database column Title */
  154. val title: Column[Option[String]] = column[Option[String]]("Title")
  155. /** Database column ReportsTo */
  156. val reportsto: Column[Option[Int]] = column[Option[Int]]("ReportsTo")
  157. /** Database column BirthDate */
  158. val birthdate: Column[Option1] = column[Option1]("BirthDate")
  159. /** Database column HireDate */
  160. val hiredate: Column[Option1] = column[Option1]("HireDate")
  161. /** Database column Address */
  162. val address: Column[Option[String]] = column[Option[String]]("Address")
  163. /** Database column City */
  164. val city: Column[Option[String]] = column[Option[String]]("City")
  165. /** Database column State */
  166. val state: Column[Option[String]] = column[Option[String]]("State")
  167. /** Database column Country */
  168. val country: Column[Option[String]] = column[Option[String]]("Country")
  169. /** Database column PostalCode */
  170. val postalcode: Column[Option[String]] = column[Option[String]]("PostalCode")
  171. /** Database column Phone */
  172. val phone: Column[Option[String]] = column[Option[String]]("Phone")
  173. /** Database column Fax */
  174. val fax: Column[Option[String]] = column[Option[String]]("Fax")
  175. /** Database column Email */
  176. val email: Column[Option[String]] = column[Option[String]]("Email")
  177. /** Foreign key referencing Employee (database name FK_EmployeeReportsTo) */
  178. lazy val employeeFk = foreignKey("FK_EmployeeReportsTo", reportsto, Employee)(r => r.employeeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  179. }
  180. /** Collection-like TableQuery object for table Employee */
  181. lazy val Employee = new TableQuery(tag => new Employee(tag))
  182. /** Entity class storing rows of table Genre
  183. * @param genreid Database column GenreId PrimaryKey
  184. * @param name Database column Name */
  185. case class GenreRow(genreid: Int, name: Option[String])
  186. /** GetResult implicit for fetching GenreRow objects using plain SQL queries */
  187. implicit def GetResultGenreRow(implicit e0: GR[Int], e1: GR[Option[String]]): GR[GenreRow] = GR{
  188. prs => import prs._
  189. GenreRow.tupled((<<[Int], <<?[String]))
  190. }
  191. /** Table description of table Genre. Objects of this class serve as prototypes for rows in queries. */
  192. class Genre(tag: Tag) extends Table[GenreRow](tag, "Genre") {
  193. def * = (genreid, name) <> (GenreRow.tupled, GenreRow.unapply)
  194. /** Maps whole row to an option. Useful for outer joins. */
  195. def ? = (genreid.?, name).shaped.<>({r=>import r._; _1.map(_=> GenreRow.tupled((_1.get, _2)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  196. /** Database column GenreId PrimaryKey */
  197. val genreid: Column[Int] = column[Int]("GenreId", O.PrimaryKey)
  198. /** Database column Name */
  199. val name: Column[Option[String]] = column[Option[String]]("Name")
  200. }
  201. /** Collection-like TableQuery object for table Genre */
  202. lazy val Genre = new TableQuery(tag => new Genre(tag))
  203. /** Entity class storing rows of table Invoice
  204. * @param invoiceid Database column InvoiceId PrimaryKey
  205. * @param customerid Database column CustomerId
  206. * @param invoicedate Database column InvoiceDate
  207. * @param billingaddress Database column BillingAddress
  208. * @param billingcity Database column BillingCity
  209. * @param billingstate Database column BillingState
  210. * @param billingcountry Database column BillingCountry
  211. * @param billingpostalcode Database column BillingPostalCode
  212. * @param total Database column Total */
  213. case class InvoiceRow(invoiceid: Int, customerid: Int, invoicedate: java.sql.Timestamp, billingaddress: Option[String], billingcity: Option[String], billingstate: Option[String], billingcountry: Option[String], billingpostalcode: Option[String], total: scala.math.BigDecimal)
  214. /** GetResult implicit for fetching InvoiceRow objects using plain SQL queries */
  215. implicit def GetResultInvoiceRow(implicit e0: GR[Int], e1: GR1, e2: GR[Option[String]], e3: GR1): GR[InvoiceRow] = GR{
  216. prs => import prs._
  217. InvoiceRow.tupled((<<[Int], <<[Int], <<1, <<?[String], <<?[String], <<?[String], <<?[String], <<?[String], <<1))
  218. }
  219. /** Table description of table Invoice. Objects of this class serve as prototypes for rows in queries. */
  220. class Invoice(tag: Tag) extends Table[InvoiceRow](tag, "Invoice") {
  221. def * = (invoiceid, customerid, invoicedate, billingaddress, billingcity, billingstate, billingcountry, billingpostalcode, total) <> (InvoiceRow.tupled, InvoiceRow.unapply)
  222. /** Maps whole row to an option. Useful for outer joins. */
  223. def ? = (invoiceid.?, customerid.?, invoicedate.?, billingaddress, billingcity, billingstate, billingcountry, billingpostalcode, total.?).shaped.<>({r=>import r._; _1.map(_=> InvoiceRow.tupled((_1.get, _2.get, _3.get, _4, _5, _6, _7, _8, _9.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  224. /** Database column InvoiceId PrimaryKey */
  225. val invoiceid: Column[Int] = column[Int]("InvoiceId", O.PrimaryKey)
  226. /** Database column CustomerId */
  227. val customerid: Column[Int] = column[Int]("CustomerId")
  228. /** Database column InvoiceDate */
  229. val invoicedate: Column1 = column1("InvoiceDate")
  230. /** Database column BillingAddress */
  231. val billingaddress: Column[Option[String]] = column[Option[String]]("BillingAddress")
  232. /** Database column BillingCity */
  233. val billingcity: Column[Option[String]] = column[Option[String]]("BillingCity")
  234. /** Database column BillingState */
  235. val billingstate: Column[Option[String]] = column[Option[String]]("BillingState")
  236. /** Database column BillingCountry */
  237. val billingcountry: Column[Option[String]] = column[Option[String]]("BillingCountry")
  238. /** Database column BillingPostalCode */
  239. val billingpostalcode: Column[Option[String]] = column[Option[String]]("BillingPostalCode")
  240. /** Database column Total */
  241. val total: Column1 = column1("Total")
  242. /** Foreign key referencing Customer (database name FK_InvoiceCustomerId) */
  243. lazy val customerFk = foreignKey("FK_InvoiceCustomerId", customerid, Customer)(r => r.customerid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  244. }
  245. /** Collection-like TableQuery object for table Invoice */
  246. lazy val Invoice = new TableQuery(tag => new Invoice(tag))
  247. /** Entity class storing rows of table Invoiceline
  248. * @param invoicelineid Database column InvoiceLineId PrimaryKey
  249. * @param invoiceid Database column InvoiceId
  250. * @param trackid Database column TrackId
  251. * @param unitprice Database column UnitPrice
  252. * @param quantity Database column Quantity */
  253. case class InvoicelineRow(invoicelineid: Int, invoiceid: Int, trackid: Int, unitprice: scala.math.BigDecimal, quantity: Int)
  254. /** GetResult implicit for fetching InvoicelineRow objects using plain SQL queries */
  255. implicit def GetResultInvoicelineRow(implicit e0: GR[Int], e1: GR1): GR[InvoicelineRow] = GR{
  256. prs => import prs._
  257. InvoicelineRow.tupled((<<[Int], <<[Int], <<[Int], <<1, <<[Int]))
  258. }
  259. /** Table description of table InvoiceLine. Objects of this class serve as prototypes for rows in queries. */
  260. class Invoiceline(tag: Tag) extends Table[InvoicelineRow](tag, "InvoiceLine") {
  261. def * = (invoicelineid, invoiceid, trackid, unitprice, quantity) <> (InvoicelineRow.tupled, InvoicelineRow.unapply)
  262. /** Maps whole row to an option. Useful for outer joins. */
  263. def ? = (invoicelineid.?, invoiceid.?, trackid.?, unitprice.?, quantity.?).shaped.<>({r=>import r._; _1.map(_=> InvoicelineRow.tupled((_1.get, _2.get, _3.get, _4.get, _5.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  264. /** Database column InvoiceLineId PrimaryKey */
  265. val invoicelineid: Column[Int] = column[Int]("InvoiceLineId", O.PrimaryKey)
  266. /** Database column InvoiceId */
  267. val invoiceid: Column[Int] = column[Int]("InvoiceId")
  268. /** Database column TrackId */
  269. val trackid: Column[Int] = column[Int]("TrackId")
  270. /** Database column UnitPrice */
  271. val unitprice: Column1 = column1("UnitPrice")
  272. /** Database column Quantity */
  273. val quantity: Column[Int] = column[Int]("Quantity")
  274. /** Foreign key referencing Invoice (database name FK_InvoiceLineInvoiceId) */
  275. lazy val invoiceFk = foreignKey("FK_InvoiceLineInvoiceId", invoiceid, Invoice)(r => r.invoiceid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  276. /** Foreign key referencing Track (database name FK_InvoiceLineTrackId) */
  277. lazy val trackFk = foreignKey("FK_InvoiceLineTrackId", trackid, Track)(r => r.trackid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  278. }
  279. /** Collection-like TableQuery object for table Invoiceline */
  280. lazy val Invoiceline = new TableQuery(tag => new Invoiceline(tag))
  281. /** Entity class storing rows of table Mediatype
  282. * @param mediatypeid Database column MediaTypeId PrimaryKey
  283. * @param name Database column Name */
  284. case class MediatypeRow(mediatypeid: Int, name: Option[String])
  285. /** GetResult implicit for fetching MediatypeRow objects using plain SQL queries */
  286. implicit def GetResultMediatypeRow(implicit e0: GR[Int], e1: GR[Option[String]]): GR[MediatypeRow] = GR{
  287. prs => import prs._
  288. MediatypeRow.tupled((<<[Int], <<?[String]))
  289. }
  290. /** Table description of table MediaType. Objects of this class serve as prototypes for rows in queries. */
  291. class Mediatype(tag: Tag) extends Table[MediatypeRow](tag, "MediaType") {
  292. def * = (mediatypeid, name) <> (MediatypeRow.tupled, MediatypeRow.unapply)
  293. /** Maps whole row to an option. Useful for outer joins. */
  294. def ? = (mediatypeid.?, name).shaped.<>({r=>import r._; _1.map(_=> MediatypeRow.tupled((_1.get, _2)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  295. /** Database column MediaTypeId PrimaryKey */
  296. val mediatypeid: Column[Int] = column[Int]("MediaTypeId", O.PrimaryKey)
  297. /** Database column Name */
  298. val name: Column[Option[String]] = column[Option[String]]("Name")
  299. }
  300. /** Collection-like TableQuery object for table Mediatype */
  301. lazy val Mediatype = new TableQuery(tag => new Mediatype(tag))
  302. /** Entity class storing rows of table Playlist
  303. * @param playlistid Database column PlaylistId PrimaryKey
  304. * @param name Database column Name */
  305. case class PlaylistRow(playlistid: Int, name: Option[String])
  306. /** GetResult implicit for fetching PlaylistRow objects using plain SQL queries */
  307. implicit def GetResultPlaylistRow(implicit e0: GR[Int], e1: GR[Option[String]]): GR[PlaylistRow] = GR{
  308. prs => import prs._
  309. PlaylistRow.tupled((<<[Int], <<?[String]))
  310. }
  311. /** Table description of table Playlist. Objects of this class serve as prototypes for rows in queries. */
  312. class Playlist(tag: Tag) extends Table[PlaylistRow](tag, "Playlist") {
  313. def * = (playlistid, name) <> (PlaylistRow.tupled, PlaylistRow.unapply)
  314. /** Maps whole row to an option. Useful for outer joins. */
  315. def ? = (playlistid.?, name).shaped.<>({r=>import r._; _1.map(_=> PlaylistRow.tupled((_1.get, _2)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  316. /** Database column PlaylistId PrimaryKey */
  317. val playlistid: Column[Int] = column[Int]("PlaylistId", O.PrimaryKey)
  318. /** Database column Name */
  319. val name: Column[Option[String]] = column[Option[String]]("Name")
  320. }
  321. /** Collection-like TableQuery object for table Playlist */
  322. lazy val Playlist = new TableQuery(tag => new Playlist(tag))
  323. /** Entity class storing rows of table Playlisttrack
  324. * @param playlistid Database column PlaylistId
  325. * @param trackid Database column TrackId */
  326. case class PlaylisttrackRow(playlistid: Int, trackid: Int)
  327. /** GetResult implicit for fetching PlaylisttrackRow objects using plain SQL queries */
  328. implicit def GetResultPlaylisttrackRow(implicit e0: GR[Int]): GR[PlaylisttrackRow] = GR{
  329. prs => import prs._
  330. PlaylisttrackRow.tupled((<<[Int], <<[Int]))
  331. }
  332. /** Table description of table PlaylistTrack. Objects of this class serve as prototypes for rows in queries. */
  333. class Playlisttrack(tag: Tag) extends Table[PlaylisttrackRow](tag, "PlaylistTrack") {
  334. def * = (playlistid, trackid) <> (PlaylisttrackRow.tupled, PlaylisttrackRow.unapply)
  335. /** Maps whole row to an option. Useful for outer joins. */
  336. def ? = (playlistid.?, trackid.?).shaped.<>({r=>import r._; _1.map(_=> PlaylisttrackRow.tupled((_1.get, _2.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  337. /** Database column PlaylistId */
  338. val playlistid: Column[Int] = column[Int]("PlaylistId")
  339. /** Database column TrackId */
  340. val trackid: Column[Int] = column[Int]("TrackId")
  341. /** Primary key of Playlisttrack (database name PlaylistTrack_PK) */
  342. val pk = primaryKey("PlaylistTrack_PK", (playlistid, trackid))
  343. /** Foreign key referencing Playlist (database name FK_PlaylistTrackPlaylistId) */
  344. lazy val playlistFk = foreignKey("FK_PlaylistTrackPlaylistId", playlistid, Playlist)(r => r.playlistid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  345. /** Foreign key referencing Track (database name FK_PlaylistTrackTrackId) */
  346. lazy val trackFk = foreignKey("FK_PlaylistTrackTrackId", trackid, Track)(r => r.trackid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  347. }
  348. /** Collection-like TableQuery object for table Playlisttrack */
  349. lazy val Playlisttrack = new TableQuery(tag => new Playlisttrack(tag))
  350. /** Entity class storing rows of table Track
  351. * @param trackid Database column TrackId PrimaryKey
  352. * @param name Database column Name
  353. * @param albumid Database column AlbumId
  354. * @param mediatypeid Database column MediaTypeId
  355. * @param genreid Database column GenreId
  356. * @param composer Database column Composer
  357. * @param milliseconds Database column Milliseconds
  358. * @param bytes Database column Bytes
  359. * @param unitprice Database column UnitPrice */
  360. case class TrackRow(trackid: Int, name: String, albumid: Option[Int], mediatypeid: Int, genreid: Option[Int], composer: Option[String], milliseconds: Int, bytes: Option[Int], unitprice: scala.math.BigDecimal)
  361. /** GetResult implicit for fetching TrackRow objects using plain SQL queries */
  362. implicit def GetResultTrackRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[Int]], e3: GR[Option[String]], e4: GR1): GR[TrackRow] = GR{
  363. prs => import prs._
  364. TrackRow.tupled((<<[Int], <<[String], <<?[Int], <<[Int], <<?[Int], <<?[String], <<[Int], <<?[Int], <<1))
  365. }
  366. /** Table description of table Track. Objects of this class serve as prototypes for rows in queries. */
  367. class Track(tag: Tag) extends Table[TrackRow](tag, "Track") {
  368. def * = (trackid, name, albumid, mediatypeid, genreid, composer, milliseconds, bytes, unitprice) <> (TrackRow.tupled, TrackRow.unapply)
  369. /** Maps whole row to an option. Useful for outer joins. */
  370. def ? = (trackid.?, name.?, albumid, mediatypeid.?, genreid, composer, milliseconds.?, bytes, unitprice.?).shaped.<>({r=>import r._; _1.map(_=> TrackRow.tupled((_1.get, _2.get, _3, _4.get, _5, _6, _7.get, _8, _9.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
  371. /** Database column TrackId PrimaryKey */
  372. val trackid: Column[Int] = column[Int]("TrackId", O.PrimaryKey)
  373. /** Database column Name */
  374. val name: Column[String] = column[String]("Name")
  375. /** Database column AlbumId */
  376. val albumid: Column[Option[Int]] = column[Option[Int]]("AlbumId")
  377. /** Database column MediaTypeId */
  378. val mediatypeid: Column[Int] = column[Int]("MediaTypeId")
  379. /** Database column GenreId */
  380. val genreid: Column[Option[Int]] = column[Option[Int]]("GenreId")
  381. /** Database column Composer */
  382. val composer: Column[Option[String]] = column[Option[String]]("Composer")
  383. /** Database column Milliseconds */
  384. val milliseconds: Column[Int] = column[Int]("Milliseconds")
  385. /** Database column Bytes */
  386. val bytes: Column[Option[Int]] = column[Option[Int]]("Bytes")
  387. /** Database column UnitPrice */
  388. val unitprice: Column1 = column1("UnitPrice")
  389. /** Foreign key referencing Album (database name FK_TrackAlbumId) */
  390. lazy val albumFk = foreignKey("FK_TrackAlbumId", albumid, Album)(r => r.albumid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  391. /** Foreign key referencing Genre (database name FK_TrackGenreId) */
  392. lazy val genreFk = foreignKey("FK_TrackGenreId", genreid, Genre)(r => r.genreid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  393. /** Foreign key referencing Mediatype (database name FK_TrackMediaTypeId) */
  394. lazy val mediatypeFk = foreignKey("FK_TrackMediaTypeId", mediatypeid, Mediatype)(r => r.mediatypeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction)
  395. }
  396. /** Collection-like TableQuery object for table Track */
  397. lazy val Track = new TableQuery(tag => new Track(tag))
  398. }
  399.