如何评价slick这个java 数据库框架架

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&Slick编程简介&&categories:&&tags:&&author:Slick对于Scala来说,有如LINQ至于C# ,或者类似于其它平台上的ORM系统,它使用应用使用数据库有如使用Scala内置的集合类型(比如列表,集合等)一样方便。当然如有需要你还是可以直接使用SQL语句来查询数据库。 下面为使用Slick的代码片段: 1
val limit = 10.0 2 3
// Your query could look like this: 4
( for( c &- if c.price & limit ) yield c.name ).list 5 6
// Or using more plain SQL String Interpolation: 7
sql&#8221;select COF_NAME from COFFEES where PRICE & $limit&#8221;.as[String].list 8 9
// Both queries result in SQL equivalent to: 10
// select COF_NAME from COFFEES where PRICE & 10.0使用Slick而不直接使用SQL语句,可以使用编译器帮助发现一些类型错误,同时Slick可以为不同的后台数据库类型生成查询。 它具有如下的一些特定: Scala 所有查询,表格和字段映射,以及类型都采用普通的Scala语法。 1
class Coffees(tag: Tag) extends Table[(String, Double)](tag, &#8220;COFFEES&#8221;) { 2
def name = column[String](&#8220;COF_NAME&#8221;, O.PrimaryKey) 3
def price = column[Double](&#8220;PRICE&#8221;) 4
def * = (name, price) 5
val coffees = TableQuery[Coffees]数据访问接口类型Scala的集合类型 1
// Query that only returns the &#8220;name&#8221; column 2
coffees.map(_.name) 3 4
// Query that does a &#8220;where price & 10.0&#8243; 5
coffees.filter(_.price & 10.0)类型安全 你使用的IDE可以帮助你写代码 在编译时而无需到运行时就可以发现一些错误 1
// The result of &#8220;select PRICE from COFFEES&#8221; is a Seq of Double 2
// because of the type safe column definitions 3
val coffeeNames: Seq[Double] = coffees.map(_.price).list 4 5
// Query builders are type safe: 6
coffees.filter(_.price & 10.0) 7
// Using a string in the filter would result in a compilation error可以组合 查询接口为函数,这些函数可以多次组合和重用。 1
// Create a query for coffee names with a price less than 10, sorted by name 2
coffees.filter(_.price & 10.0).sortBy(_.name).map(_.name) 3
// The generated SQL is equivalent to: 4
// select name from COFFEES where PRICE & 10.0 order by NAME支持的数据库系统DB2 (via slick-extensions)Derby/JavaDBH2HSQLDB/HyperSQLMicrosoft AccessMicrosoft SQL Server (via slick-extensions)MySQLOracle (via slick-extensions)PostgreSQLSQLite对于其它的一些数据库类型Slick也提供了有限的支持。查询接口Lifted Embedding Sclick 使用Lifted Embedding作为标准的数据库查询接口,此外Direct Embedding接口正在开发测试当中。 Lifted Embedding的名称来自于,你不是使用标准的Scala数据类型来访问查询数据库,而是使用Rep构造器来提升(Lift)Scala的基本数据类型,然后使用提升后的数据类型来访问数据库,比如标准的Scala集合的例子: 1
case class Coffee(name: String, price: Double) 2
val coffees: List[Coffee] = //&#8230; 3 4
val l = coffees.filter(_.price & 8.0).map(_.name) 5
String而对应的提升之后的例子: 1
class Coffees(tag: Tag) extends Table[(String, Double)](tag, &#8220;COFFEES&#8221;) { 2
def name = column[String](&#8220;COF_NAME&#8221;) 3
def price = column[Double](&#8220;PRICE&#8221;) 4
def * = (name, price) 5
val coffees = TableQuery[Coffees] 7 8
val q = coffees.filter(_.price & 8.0).map(_.name) 9
Rep[Double]
Rep[Double]
Rep[String]所有的基本Scala类型,都提升为Rep。即使是8.0字面量也被提升为Rep[Double]类型。 后面的例子,我们会采用Chinook数据库作为例子。Chinook 数据库模型。Chinook数据库前身为著名的Northwind数据库,它的数据模型如下:&Slick 编程(2): 准备开发环境本篇介绍如果设置使用Slick的Scala开发环境,这里我们使用SBT命令行,SBT使用的目录结构和Maven一样,我们可以创建一个目录,比如Slick,然后创建如下的缺省目录结构:src main java resources scala test java resources scala因为我们打算使用MySQL数据库,并使用Slick来访问数据库,因此我们在Slick的根目录下创建一个build.sbt,添加相关引用: 1
name := &#8220;Scala Slick Examples&#8221; 2 3
version := &#&#8221; 4 5
scalaVersion := &#.4&#8221; 6 7
libraryDependencies += &#8220;com.typesafe.slick&#8221; %% &#8220;slick&#8221; % &#.2&#8221; 8 9
libraryDependencies += &#8220;org.slf4j&#8221; % &#8220;slf4j-nop&#8221; % &#.4&#8221; 10 11
libraryDependencies += &#8220;mysql&#8221; % &#8220;mysql-connector-java&#8221; % &#.18&#8221;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(&#8220;scala.slick.driver.MySQLDriver&#8221;, &#8220;com.mysql.jdbc.Driver&#8221;, 3
&#8220;jdbc:mysql://127.0.0.1/Chinook&#8221;, 4
&#8220;./src/main/scala&#8221;, 5
&#8220;com.guidebee.slick.example&#8221;, &#8220;user&#8221;, &#8220;password&#8221;) 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 16
/** DDL for all tables. Call .create to execute. */ 17
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 18 19
/** Entity class storing rows of table Album 20
@param albumid Database column AlbumId PrimaryKey 21
@param title Database column Title 22
@param artistid Database column ArtistId
case class AlbumRow(albumid: Int, title: String, artistid: Int) 24
/** GetResult implicit for fetching AlbumRow objects using plain SQL queries */ 25
implicit def GetResultAlbumRow(implicit e0: GR[Int], e1: GR[String]):GR[AlbumRow] = GR{ 26
prs =& import prs._ 27
AlbumRow.tupled((&&[Int], &&[String], &&[Int])) 28
/** Table description of table Album. Objects of this class serve as prototypes for rows in queries. */ 30
class Album(tag: Tag) extends Table[AlbumRow](tag, &#8220;Album&#8221;) { 31
def * = (albumid, title, artistid) && (AlbumRow.tupled, AlbumRow.unapply) 32
/** Maps whole row to an option. Useful for outer joins. */ 33
def ? = (albumid.?, title.?, artistid.?).shaped.&&({r=&import r._;_1.map(_=& AlbumRow.tupled((_1.get, _2.get, _3.get)))}, (_:Any) =& throw new Exception(&#8220;Inserting into ? projection not supported.&#8221;)) 34 35
/** Database column AlbumId PrimaryKey */ 36
val albumid: Column[Int] = column[Int](&#8220;AlbumId&#8221;, O.PrimaryKey) 37
/** Database column Title
val title: Column[String] = column[String](&#8220;Title&#8221;) 39
/** Database column ArtistId
val artistid: Column[Int] = column[Int](&#8220;ArtistId&#8221;) 41 42
/** Foreign key referencing Artist (database name FK_AlbumArtistId) */ 43
lazy val artistFk = foreignKey(&#8220;FK_AlbumArtistId&#8221;, artistid, Artist)(r =& r.artistid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 44
/** Collection-like TableQuery object for table Album */ 46
lazy val Album = new TableQuery(tag =& new Album(tag)) 47 48
/** Entity class storing rows of table Artist 49
@param artistid Database column ArtistId PrimaryKey 50
@param name Database column Name
case class ArtistRow(artistid: Int, name: Option[String]) 52
/** GetResult implicit for fetching ArtistRow objects using plain SQL queries */ 53
implicit def GetResultArtistRow(implicit e0: GR[Int], e1:GR[Option[String]]): GR[ArtistRow] = GR{ 54
prs =& import prs._ 55
ArtistRow.tupled((&&[Int], &&?[String])) 56
/** Table description of table Artist. Objects of this class serve as prototypes for rows in queries. */ 58
class Artist(tag: Tag) extends Table[ArtistRow](tag, &#8220;Artist&#8221;) { 59
def * = (artistid, name) && (ArtistRow.tupled, ArtistRow.unapply) 60
/** Maps whole row to an option. Useful for outer joins. */ 61
def ? = (artistid.?, name).shaped.&&({r=&import r._; _1.map(_=& ArtistRow.tupled((_1.get, _2)))}, (_:Any) =&
throw newException(&#8220;Inserting into ? projection not supported.&#8221;)) 62 63
/** Database column ArtistId PrimaryKey */ 64
val artistid: Column[Int] = column[Int](&#8220;ArtistId&#8221;, O.PrimaryKey) 65
/** Database column Name
val name: Column[Option[String]] = column[Option[String]](&#8220;Name&#8221;) 67
/** Collection-like TableQuery object for table Artist */ 69
lazy val Artist = new TableQuery(tag =& new Artist(tag)) 70 71
/** Entity class storing rows of table Customer 72
@param customerid Database column CustomerId PrimaryKey 73
@param firstname Database column FirstName 74
@param lastname Database column LastName 75
@param company Database column Company 76
@param address Database column Address 77
@param city Database column City 78
@param state Database column State 79
@param country Database column Country 80
@param postalcode Database column PostalCode 81
@param phone Database column Phone 82
@param fax Database column Fax 83
@param email Database column Email 84
@param supportrepid Database column SupportRepId
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]) 86
/** GetResult implicit for fetching CustomerRow objects using plain SQL queries */ 87
implicit def GetResultCustomerRow(implicit e0: GR[Int], e1:GR[String], e2: GR[Option[String]], e3: GR[Option[Int]]):GR[CustomerRow] = GR{ 88
prs =& import prs._ 89
CustomerRow.tupled((&&[Int], &&[String], &&[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&[String], &&?[Int])) 90
/** Table description of table Customer. Objects of this class serve as prototypes for rows in queries. */ 92
class Customer(tag: Tag) extends Table[CustomerRow](tag, &#8220;Customer&#8221;) { 93
def * = (customerid, firstname, lastname, company, address, city, state, country, postalcode, phone, fax, email, supportrepid) && (CustomerRow.tupled, CustomerRow.unapply) 94
/** Maps whole row to an option. Useful for outer joins. */ 95
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(&#8220;Inserting into ? projection not supported.&#8221;)) 96 97
/** Database column CustomerId PrimaryKey */ 98
val customerid: Column[Int] = column[Int](&#8220;CustomerId&#8221;, O.PrimaryKey) 99
/** Database column FirstName
val firstname: Column[String] = column[String](&#8220;FirstName&#8221;) 101
/** Database column LastName
val lastname: Column[String] = column[String](&#8220;LastName&#8221;) 103
/** Database column Company
val company: Column[Option[String]] = column[Option[String]](&#8220;Company&#8221;) 105
/** Database column Address
val address: Column[Option[String]] = column[Option[String]](&#8220;Address&#8221;) 107
/** Database column City
val city: Column[Option[String]] = column[Option[String]](&#8220;City&#8221;) 109
/** Database column State
val state: Column[Option[String]] = column[Option[String]](&#8220;State&#8221;) 111
/** Database column Country
val country: Column[Option[String]] = column[Option[String]](&#8220;Country&#8221;) 113
/** Database column PostalCode
val postalcode: Column[Option[String]] = column[Option[String]](&#8220;PostalCode&#8221;) 115
/** Database column Phone
val phone: Column[Option[String]] = column[Option[String]](&#8220;Phone&#8221;) 117
/** Database column Fax
val fax: Column[Option[String]] = column[Option[String]](&#8220;Fax&#8221;) 119
/** Database column Email
val email: Column[String] = column[String](&#8220;Email&#8221;) 121
/** Database column SupportRepId
val supportrepid: Column[Option[Int]] = column[Option[Int]](&#8220;SupportRepId&#8221;) 123 124
/** Foreign key referencing Employee (database name FK_CustomerSupportRepId) */ 125
lazy val employeeFk = foreignKey(&#8220;FK_CustomerSupportRepId&#8221;, supportrepid, Employee)(r =& r.employeeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 126
/** Collection-like TableQuery object for table Customer */ 128
lazy val Customer = new TableQuery(tag =& new Customer(tag)) 129 130
/** Entity class storing rows of table Employee 131
@param employeeid Database column EmployeeId PrimaryKey 132
@param lastname Database column LastName 133
@param firstname Database column FirstName 134
@param title Database column Title 135
@param reportsto Database column ReportsTo 136
@param birthdate Database column BirthDate 137
@param hiredate Database column HireDate 138
@param address Database column Address 139
@param city Database column City 140
@param state Database column State 141
@param country Database column Country 142
@param postalcode Database column PostalCode 143
@param phone Database column Phone 144
@param fax Database column Fax 145
@param email Database column Email
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]) 147
/** GetResult implicit for fetching EmployeeRow objects using plain SQL queries */ 148
implicit def GetResultEmployeeRow(implicit e0: GR[Int], e1:GR[String], e2: GR[Option[String]], e3: GR[Option[Int]], e4:GR[Option1]): GR[EmployeeRow] = GR{ 149
prs =& import prs._ 150
EmployeeRow.tupled((&&[Int], &&[String], &&[String], &&?[String], &&?[Int], &&?1, &&?1, &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&?[String])) 151
/** Table description of table Employee. Objects of this class serve as prototypes for rows in queries. */ 153
class Employee(tag: Tag) extends Table[EmployeeRow](tag, &#8220;Employee&#8221;) { 154
def * = (employeeid, lastname, firstname, title, reportsto, birthdate, hiredate, address, city, state, country, postalcode, phone, fax, email) && (EmployeeRow.tupled, EmployeeRow.unapply) 155
/** Maps whole row to an option. Useful for outer joins. */ 156
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 newException(&#8220;Inserting into ? projection not supported.&#8221;)) 157 158
/** Database column EmployeeId PrimaryKey */ 159
val employeeid: Column[Int] = column[Int](&#8220;EmployeeId&#8221;, O.PrimaryKey) 160
/** Database column LastName
val lastname: Column[String] = column[String](&#8220;LastName&#8221;) 162
/** Database column FirstName
val firstname: Column[String] = column[String](&#8220;FirstName&#8221;) 164
/** Database column Title
val title: Column[Option[String]] = column[Option[String]](&#8220;Title&#8221;) 166
/** Database column ReportsTo
val reportsto: Column[Option[Int]] = column[Option[Int]](&#8220;ReportsTo&#8221;) 168
/** Database column BirthDate
val birthdate: Column[Option1] = column[Option1](&#8220;BirthDate&#8221;) 170
/** Database column HireDate
val hiredate: Column[Option1] = column[Option1](&#8220;HireDate&#8221;) 172
/** Database column Address
val address: Column[Option[String]] = column[Option[String]](&#8220;Address&#8221;) 174
/** Database column City
val city: Column[Option[String]] = column[Option[String]](&#8220;City&#8221;) 176
/** Database column State
val state: Column[Option[String]] = column[Option[String]](&#8220;State&#8221;) 178
/** Database column Country
val country: Column[Option[String]] = column[Option[String]](&#8220;Country&#8221;) 180
/** Database column PostalCode
val postalcode: Column[Option[String]] = column[Option[String]](&#8220;PostalCode&#8221;) 182
/** Database column Phone
val phone: Column[Option[String]] = column[Option[String]](&#8220;Phone&#8221;) 184
/** Database column Fax
val fax: Column[Option[String]] = column[Option[String]](&#8220;Fax&#8221;) 186
/** Database column Email
val email: Column[Option[String]] = column[Option[String]](&#8220;Email&#8221;) 188 189
/** Foreign key referencing Employee (database name FK_EmployeeReportsTo) */ 190
lazy val employeeFk = foreignKey(&#8220;FK_EmployeeReportsTo&#8221;, reportsto, Employee)(r =& r.employeeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 191
/** Collection-like TableQuery object for table Employee */ 193
lazy val Employee = new TableQuery(tag =& new Employee(tag)) 194 195
/** Entity class storing rows of table Genre 196
@param genreid Database column GenreId PrimaryKey 197
@param name Database column Name
case class GenreRow(genreid: Int, name: Option[String]) 199
/** GetResult implicit for fetching GenreRow objects using plain SQL queries */ 200
implicit def GetResultGenreRow(implicit e0: GR[Int], e1:GR[Option[String]]): GR[GenreRow] = GR{ 201
prs =& import prs._ 202
GenreRow.tupled((&&[Int], &&?[String])) 203
/** Table description of table Genre. Objects of this class serve as prototypes for rows in queries. */ 205
class Genre(tag: Tag) extends Table[GenreRow](tag, &#8220;Genre&#8221;) { 206
def * = (genreid, name) && (GenreRow.tupled, GenreRow.unapply) 207
/** Maps whole row to an option. Useful for outer joins. */ 208
def ? = (genreid.?, name).shaped.&&({r=&import r._; _1.map(_=& GenreRow.tupled((_1.get, _2)))}, (_:Any) =&
throw newException(&#8220;Inserting into ? projection not supported.&#8221;)) 209 210
/** Database column GenreId PrimaryKey */ 211
val genreid: Column[Int] = column[Int](&#8220;GenreId&#8221;, O.PrimaryKey) 212
/** Database column Name
val name: Column[Option[String]] = column[Option[String]](&#8220;Name&#8221;) 214
/** Collection-like TableQuery object for table Genre */ 216
lazy val Genre = new TableQuery(tag =& new Genre(tag)) 217 218
/** Entity class storing rows of table Invoice 219
@param invoiceid Database column InvoiceId PrimaryKey 220
@param customerid Database column CustomerId 221
@param invoicedate Database column InvoiceDate 222
@param billingaddress Database column BillingAddress 223
@param billingcity Database column BillingCity 224
@param billingstate Database column BillingState 225
@param billingcountry Database column BillingCountry 226
@param billingpostalcode Database column BillingPostalCode 227
@param total Database column Total
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) 229
/** GetResult implicit for fetching InvoiceRow objects using plain SQL queries */ 230
implicit def GetResultInvoiceRow(implicit e0: GR[Int], e1: GR1, e2:GR[Option[String]], e3: GR1): GR[InvoiceRow] = GR{ 231
prs =& import prs._ 232
InvoiceRow.tupled((&&[Int], &&[Int], &&1, &&?[String], &&?[String], &&?[String], &&?[String], &&?[String], &&1)) 233
/** Table description of table Invoice. Objects of this class serve as prototypes for rows in queries. */ 235
class Invoice(tag: Tag) extends Table[InvoiceRow](tag, &#8220;Invoice&#8221;) { 236
def * = (invoiceid, customerid, invoicedate, billingaddress, billingcity, billingstate, billingcountry, billingpostalcode, total) && (InvoiceRow.tupled, InvoiceRow.unapply) 237
/** Maps whole row to an option. Useful for outer joins. */ 238
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(&#8220;Inserting into ? projection not supported.&#8221;)) 239 240
/** Database column InvoiceId PrimaryKey */ 241
val invoiceid: Column[Int] = column[Int](&#8220;InvoiceId&#8221;, O.PrimaryKey) 242
/** Database column CustomerId
val customerid: Column[Int] = column[Int](&#8220;CustomerId&#8221;) 244
/** Database column InvoiceDate
val invoicedate: Column1 = column1(&#8220;InvoiceDate&#8221;) 246
/** Database column BillingAddress
val billingaddress: Column[Option[String]] = column[Option[String]](&#8220;BillingAddress&#8221;) 248
/** Database column BillingCity
val billingcity: Column[Option[String]] = column[Option[String]](&#8220;BillingCity&#8221;) 250
/** Database column BillingState
val billingstate: Column[Option[String]] = column[Option[String]](&#8220;BillingState&#8221;) 252
/** Database column BillingCountry
val billingcountry: Column[Option[String]] = column[Option[String]](&#8220;BillingCountry&#8221;) 254
/** Database column BillingPostalCode
val billingpostalcode: Column[Option[String]] =column[Option[String]](&#8220;BillingPostalCode&#8221;) 256
/** Database column Total
val total: Column1 = column1(&#8220;Total&#8221;) 258 259
/** Foreign key referencing Customer (database name FK_InvoiceCustomerId) */ 260
lazy val customerFk = foreignKey(&#8220;FK_InvoiceCustomerId&#8221;, customerid, Customer)(r =& r.customerid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 261
/** Collection-like TableQuery object for table Invoice */ 263
lazy val Invoice = new TableQuery(tag =& new Invoice(tag)) 264 265
/** Entity class storing rows of table Invoiceline 266
@param invoicelineid Database column InvoiceLineId PrimaryKey 267
@param invoiceid Database column InvoiceId 268
@param trackid Database column TrackId 269
@param unitprice Database column UnitPrice 270
@param quantity Database column Quantity
case class InvoicelineRow(invoicelineid: Int, invoiceid: Int, trackid: Int, unitprice: scala.math.BigDecimal, quantity: Int) 272
/** GetResult implicit for fetching InvoicelineRow objects using plain SQL queries */ 273
implicit def GetResultInvoicelineRow(implicit e0: GR[Int], e1: GR1):GR[InvoicelineRow] = GR{ 274
prs =& import prs._ 275
InvoicelineRow.tupled((&&[Int], &&[Int], &&[Int], &&1, &&[Int])) 276
/** Table description of table InvoiceLine. Objects of this class serve as prototypes for rows in queries. */ 278
class Invoiceline(tag: Tag) extends Table[InvoicelineRow](tag,&#8221;InvoiceLine&#8221;) { 279
def * = (invoicelineid, invoiceid, trackid, unitprice, quantity) && (InvoicelineRow.tupled, InvoicelineRow.unapply) 280
/** Maps whole row to an option. Useful for outer joins. */ 281
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(&#8220;Inserting into ? projection not supported.&#8221;)) 282 283
/** Database column InvoiceLineId PrimaryKey */ 284
val invoicelineid: Column[Int] = column[Int](&#8220;InvoiceLineId&#8221;, O.PrimaryKey) 285
/** Database column InvoiceId
val invoiceid: Column[Int] = column[Int](&#8220;InvoiceId&#8221;) 287
/** Database column TrackId
val trackid: Column[Int] = column[Int](&#8220;TrackId&#8221;) 289
/** Database column UnitPrice
val unitprice: Column1 = column1(&#8220;UnitPrice&#8221;) 291
/** Database column Quantity
val quantity: Column[Int] = column[Int](&#8220;Quantity&#8221;) 293 294
/** Foreign key referencing Invoice (database name FK_InvoiceLineInvoiceId) */ 295
lazy val invoiceFk = foreignKey(&#8220;FK_InvoiceLineInvoiceId&#8221;, invoiceid, Invoice)(r =& r.invoiceid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 296
/** Foreign key referencing Track (database name FK_InvoiceLineTrackId) */ 297
lazy val trackFk = foreignKey(&#8220;FK_InvoiceLineTrackId&#8221;, trackid, Track)(r =& r.trackid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 298
/** Collection-like TableQuery object for table Invoiceline */ 300
lazy val Invoiceline = new TableQuery(tag =& new Invoiceline(tag)) 301 302
/** Entity class storing rows of table Mediatype 303
@param mediatypeid Database column MediaTypeId PrimaryKey 304
@param name Database column Name
case class MediatypeRow(mediatypeid: Int, name: Option[String]) 306
/** GetResult implicit for fetching MediatypeRow objects using plain SQL queries */ 307
implicit def GetResultMediatypeRow(implicit e0: GR[Int], e1:GR[Option[String]]): GR[MediatypeRow] = GR{ 308
prs =& import prs._ 309
MediatypeRow.tupled((&&[Int], &&?[String])) 310
/** Table description of table MediaType. Objects of this class serve as prototypes for rows in queries. */ 312
class Mediatype(tag: Tag) extends Table[MediatypeRow](tag,&#8221;MediaType&#8221;) { 313
def * = (mediatypeid, name) && (MediatypeRow.tupled, MediatypeRow.unapply) 314
/** Maps whole row to an option. Useful for outer joins. */ 315
def ? = (mediatypeid.?, name).shaped.&&({r=&import r._; _1.map(_=& MediatypeRow.tupled((_1.get, _2)))}, (_:Any) =&
throw newException(&#8220;Inserting into ? projection not supported.&#8221;)) 316 317
/** Database column MediaTypeId PrimaryKey */ 318
val mediatypeid: Column[Int] = column[Int](&#8220;MediaTypeId&#8221;, O.PrimaryKey) 319
/** Database column Name
val name: Column[Option[String]] = column[Option[String]](&#8220;Name&#8221;) 321
/** Collection-like TableQuery object for table Mediatype */ 323
lazy val Mediatype = new TableQuery(tag =& new Mediatype(tag)) 324 325
/** Entity class storing rows of table Playlist 326
@param playlistid Database column PlaylistId PrimaryKey 327
@param name Database column Name
case class PlaylistRow(playlistid: Int, name: Option[String]) 329
/** GetResult implicit for fetching PlaylistRow objects using plain SQL queries */ 330
implicit def GetResultPlaylistRow(implicit e0: GR[Int], e1:GR[Option[String]]): GR[PlaylistRow] = GR{ 331
prs =& import prs._ 332
PlaylistRow.tupled((&&[Int], &&?[String])) 333
/** Table description of table Playlist. Objects of this class serve as prototypes for rows in queries. */ 335
class Playlist(tag: Tag) extends Table[PlaylistRow](tag, &#8220;Playlist&#8221;) { 336
def * = (playlistid, name) && (PlaylistRow.tupled, PlaylistRow.unapply) 337
/** Maps whole row to an option. Useful for outer joins. */ 338
def ? = (playlistid.?, name).shaped.&&({r=&import r._; _1.map(_=& PlaylistRow.tupled((_1.get, _2)))}, (_:Any) =&
throw newException(&#8220;Inserting into ? projection not supported.&#8221;)) 339 340
/** Database column PlaylistId PrimaryKey */ 341
val playlistid: Column[Int] = column[Int](&#8220;PlaylistId&#8221;, O.PrimaryKey) 342
/** Database column Name
val name: Column[Option[String]] = column[Option[String]](&#8220;Name&#8221;) 344
/** Collection-like TableQuery object for table Playlist */ 346
lazy val Playlist = new TableQuery(tag =& new Playlist(tag)) 347 348
/** Entity class storing rows of table Playlisttrack 349
@param playlistid Database column PlaylistId 350
@param trackid Database column TrackId
case class PlaylisttrackRow(playlistid: Int, trackid: Int) 352
/** GetResult implicit for fetching PlaylisttrackRow objects using plain SQL queries */ 353
implicit def GetResultPlaylisttrackRow(implicit e0: GR[Int]):GR[PlaylisttrackRow] = GR{ 354
prs =& import prs._ 355
PlaylisttrackRow.tupled((&&[Int], &&[Int])) 356
/** Table description of table PlaylistTrack. Objects of this class serve as prototypes for rows in queries. */ 358
class Playlisttrack(tag: Tag) extends Table[PlaylisttrackRow](tag,&#8221;PlaylistTrack&#8221;) { 359
def * = (playlistid, trackid) && (PlaylisttrackRow.tupled, PlaylisttrackRow.unapply) 360
/** Maps whole row to an option. Useful for outer joins. */ 361
def ? = (playlistid.?, trackid.?).shaped.&&({r=&import r._;_1.map(_=& PlaylisttrackRow.tupled((_1.get, _2.get)))}, (_:Any) =& throw new Exception(&#8220;Inserting into ? projection not supported.&#8221;)) 362 363
/** Database column PlaylistId
val playlistid: Column[Int] = column[Int](&#8220;PlaylistId&#8221;) 365
/** Database column TrackId
val trackid: Column[Int] = column[Int](&#8220;TrackId&#8221;) 367 368
/** Primary key of Playlisttrack (database name PlaylistTrack_PK) */ 369
val pk = primaryKey(&#8220;PlaylistTrack_PK&#8221;, (playlistid, trackid)) 370 371
/** Foreign key referencing Playlist (database name FK_PlaylistTrackPlaylistId) */ 372
lazy val playlistFk = foreignKey(&#8220;FK_PlaylistTrackPlaylistId&#8221;, playlistid, Playlist)(r =& r.playlistid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 373
/** Foreign key referencing Track (database name FK_PlaylistTrackTrackId) */ 374
lazy val trackFk = foreignKey(&#8220;FK_PlaylistTrackTrackId&#8221;, trackid, Track)(r =& r.trackid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 375
/** Collection-like TableQuery object for table Playlisttrack */ 377
lazy val Playlisttrack = new TableQuery(tag =& newPlaylisttrack(tag)) 378 379
/** Entity class storing rows of table Track 380
@param trackid Database column TrackId PrimaryKey 381
@param name Database column Name 382
@param albumid Database column AlbumId 383
@param mediatypeid Database column MediaTypeId 384
@param genreid Database column GenreId 385
@param composer Database column Composer 386
@param milliseconds Database column Milliseconds 387
@param bytes Database column Bytes 388
@param unitprice Database column UnitPrice
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) 390
/** GetResult implicit for fetching TrackRow objects using plain SQL queries */ 391
implicit def GetResultTrackRow(implicit e0: GR[Int], e1: GR[String], e2: GR[Option[Int]], e3: GR[Option[String]], e4: GR1): GR[TrackRow] =GR{ 392
prs =& import prs._ 393
TrackRow.tupled((&&[Int], &&[String], &&?[Int], &&[Int], &&?[Int], &&?[String], &&[Int], &&?[Int], &&1)) 394
/** Table description of table Track. Objects of this class serve as prototypes for rows in queries. */ 396
class Track(tag: Tag) extends Table[TrackRow](tag, &#8220;Track&#8221;) { 397
def * = (trackid, name, albumid, mediatypeid, genreid, composer, milliseconds, bytes, unitprice) && (TrackRow.tupled, TrackRow.unapply) 398
/** Maps whole row to an option. Useful for outer joins. */ 399
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(&#8220;Inserting into ? projection not supported.&#8221;)) 400 401
/** Database column TrackId PrimaryKey */ 402
val trackid: Column[Int] = column[Int](&#8220;TrackId&#8221;, O.PrimaryKey) 403
/** Database column Name
val name: Column[String] = column[String](&#8220;Name&#8221;) 405
/** Database column AlbumId
val albumid: Column[Option[Int]] = column[Option[Int]](&#8220;AlbumId&#8221;) 407
/** Database column MediaTypeId
val mediatypeid: Column[Int] = column[Int](&#8220;MediaTypeId&#8221;) 409
/** Database column GenreId
val genreid: Column[Option[Int]] = column[Option[Int]](&#8220;GenreId&#8221;) 411
/** Database column Composer
val composer: Column[Option[String]] = column[Option[String]](&#8220;Composer&#8221;) 413
/** Database column Milliseconds
val milliseconds: Column[Int] = column[Int](&#8220;Milliseconds&#8221;) 415
/** Database column Bytes
val bytes: Column[Option[Int]] = column[Option[Int]](&#8220;Bytes&#8221;) 417
/** Database column UnitPrice
val unitprice: Column1 = column1(&#8220;UnitPrice&#8221;) 419 420
/** Foreign key referencing Album (database name FK_TrackAlbumId) */ 421
lazy val albumFk = foreignKey(&#8220;FK_TrackAlbumId&#8221;, albumid, Album)(r=& r.albumid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 422
/** Foreign key referencing Genre (database name FK_TrackGenreId) */ 423
lazy val genreFk = foreignKey(&#8220;FK_TrackGenreId&#8221;, genreid, Genre)(r=& r.genreid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 424
/** Foreign key referencing Mediatype (database name FK_TrackMediaTypeId) */ 425
lazy val mediatypeFk = foreignKey(&#8220;FK_TrackMediaTypeId&#8221;, mediatypeid, Mediatype)(r =& r.mediatypeid, onUpdate=ForeignKeyAction.NoAction, onDelete=ForeignKeyAction.NoAction) 426
/** Collection-like TableQuery object for table Track */ 428
lazy val Track = new TableQuery(tag =& new Track(tag)) 429
}&原文:http://www.scala-china.net/discuz/forum.php?mod=viewthread&tid=151252&extra=page%3D1近期文章
分类目录选择分类目录书路&&(10)儿童画&&(98)&&&儿童作品&&(82)&&&儿童画教程&&(16)原创&&(126)&&&0基础编程&&(23)&&&android&&(9)&&&hadoop&&(18)&&&java原创&&(2)&&&livewriter&&(11)&&&nginx&&(52)资料&&(874)&&&android资料&&(84)&&&java资料&&(67)&&&linux资料&&(34)&&&mysql资料&&(34)&&&nginx资料&&(17)&&&svn&&(9)&&&wordpress&&(48)&&&搜索资料&&(45) 文章归档 选择月份 2016年七月 &(2) 2016年六月 &(7) 2016年五月 &(14) 2016年四月 &(6) 2016年三月 &(20) 2016年二月 &(11) 2016年一月 &(14) 2015年十二月 &(17) 2015年十一月 &(13) 2015年十月 &(6) 2015年九月 &(6) 2015年八月 &(7) 2015年七月 &(11) 2015年六月 &(19) 2015年五月 &(26) 2015年四月 &(19) 2015年三月 &(35) 2015年二月 &(38) 2015年一月 &(20) 2014年十二月 &(8) 2014年十一月 &(8) 2014年十月 &(3) 2014年九月 &(3) 2014年八月 &(3) 2014年七月 &(4) 2014年六月 &(3) 2014年五月 &(7) 2014年四月 &(10) 2014年三月 &(8) 2014年二月 &(8) 2014年一月 &(11) 2013年十二月 &(11) 2013年十一月 &(9) 2013年十月 &(40) 2013年九月 &(79) 2013年八月 &(50) 2013年七月 &(68) 2013年六月 &(50) 2013年五月 &(59) 2013年四月 &(65) 2013年三月 &(59) 2013年二月 &(20) 2013年一月 &(59) 2012年十二月 &(52) 2012年十一月 &(91) 2012年十月 &(23)

我要回帖

更多关于 java数据库操作框架 的文章

 

随机推荐