课程表

Slick课程

工具箱
速查手册

Slick 准备开发环境

当前位置:免费教程 » 数据库/运维 » Slick

准备开发环境

本篇介绍如果设置使用 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. version := "1.0"
  3. scalaVersion := "2.10.4"
  4. libraryDependencies += "com.typesafe.slick" %% "slick" % "2.0.2"
  5. libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.6.4"
  6. libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.18"

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

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号