- 浏览: 2566793 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Slick(1)Introduce and Documents
The current release is Slick 0.11.2 for Scala 2.10.0-RC1.
Supported database systems
No Oracle but
Derby/JavaDB
H2
HSQLDB/HyperSQL
Microsoft Access
MySQL
PostgreSQL
SQLite
Getting Started
Start from the Example
>git clone https://github.com/slick/slick-examples.git
>cd slick-examples
>sbt update
>sbt run
>sbt eclipse
Import this project to eclipse and start to learn.
Overview
Four steps to use this
1. Add the Slick jar and dependencies
2. Pick a driver for a particular db
import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession
3. Describe the Database schema
object Coffees extends Table[(String, Double)]("COFFEES"){
def name = column[String]("COF_NAME", O.PrimaryKey)
def price = column[Double]("PRICE")
def * = name ~ price
}
4. Write queries
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
Coffees.filter(_.price < 10.0).map(_.name).list
}
Dependencies
I will just make this example happen on my easy spray project.
"com.typesafe" % "slick_2.10.0-RC2" % "0.11.2",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.h2database" % "h2" % "1.3.170",
"org.xerial" % "sqlite-jdbc" % "3.6.20",
"mysql" % "mysql-connector-java" % "5.1.13"
/*
"org.apache.derby" % "derby" % "10.6.1.0",
"org.hsqldb" % "hsqldb" % "2.0.0",
"postgresql" % "postgresql" % "8.4-701.jdbc4",
"mysql" % "mysql-connector-java" % "5.1.13"
*/
Imports
Take the example in project slick-examples/src/main/scala/scala.slick.examples.lifted.FirstExample
And make sure we do not use the master, we need to use the tag branch 0.11.2.
// Use H2Driver to connect to an H2 database
import scala.slick.driver.H2Driver.simple._
// Use the implicit threadLocalSession
import Database.threadLocalSession
Database Connection
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
…snip…
}
Schema Definition with Forekey
object Suppliers extends Table[(Int, String, String, String, String, String)]("SUPPLIERS") {
def id = column[Int]("SUP_ID", O.PrimaryKey) // 1 This is the primary key column
def name = column[String]("SUP_NAME") // 2
def street = column[String]("STREET") //3
def city = column[String]("CITY") //4
def state = column[String]("STATE") //5
def zip = column[String]("ZIP") // 6
def * = id ~ name ~ street ~ city ~ state ~ zip
}
object Coffees extends Table[(String, Int, Double, Int, Int)]("COFFEES") {
def name = column[String]("COF_NAME", O.PrimaryKey) //1
def supID = column[Int]("SUP_ID") //2
def price = column[Double]("PRICE") //3
def sales = column[Int]("SALES") //4
def total = column[Int]("TOTAL") //5
def * = name ~ supID ~ price ~ sales ~ total
def supplier = foreignKey("SUP_FK", supID, Suppliers)(_.id)
}
Populating the Database
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
(Suppliers.ddl ++ Coffees.ddl).create
Suppliers.insert(1, "Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
Suppliers.insert(2, "Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460")
Suppliers.insert(3, "The High Ground", "100 Coffee Lane", "Meadows", "CA", "93966")
Coffees.insertAll(
("Colombian", 1, 7.99, 0, 0),
("French_Roast", 3, 8.99, 0, 0),
("Espresso", 2, 9.99, 0, 0),
("Colombian_Decaf", 2, 8.99, 0, 0),
("French_Roast_Decaf", 1, 9.99, 0, 0))
}
Querying
Query(TableName) foreach show up all the data in one table
println("Coffees:")
Query(Coffees) foreach {
case (name, supID, price, sales, total) =>
println(" " + name + "\t" + supID + "\t" + price + "\t" + sales + "\t" + total)
}
println("Manual join:")
val q2 = for {
c <- Coffees if c.price < 9.0 //table 1 with price condition
s <- Suppliers if s.id === c.supID //table 2 with join id
} yield (c.name, s.name)
for (t <- q2) println(" " + t._1 + " supplied by " + t._2)
println("Join by foreign key:")
val q3 = for {
c <- Coffees if c.price < 9.0
s <- c.supplier
} yield (c.name, s.name)
// This time we read the result set into a List
val l3: List[(String, String)] = q3.list
for ((s1, s2) <- l3) println(" " + s1 + " supplied by " + s2)
println(q3.selectStatement)
select x2."COF_NAME", x3."SUP_NAME" from "COFFEES" x2, "SUPPLIERS" x3 where (x2."PRICE" < 9.0) and (x3."SUP_ID" = x2."SUP_ID")
References:
http://slick.typesafe.com/
http://slick.typesafe.com/docs/
http://slick.typesafe.com/doc/0.11.2/
http://slick.typesafe.com/doc/0.11.2/gettingstarted.html
The current release is Slick 0.11.2 for Scala 2.10.0-RC1.
Supported database systems
No Oracle but
Derby/JavaDB
H2
HSQLDB/HyperSQL
Microsoft Access
MySQL
PostgreSQL
SQLite
Getting Started
Start from the Example
>git clone https://github.com/slick/slick-examples.git
>cd slick-examples
>sbt update
>sbt run
>sbt eclipse
Import this project to eclipse and start to learn.
Overview
Four steps to use this
1. Add the Slick jar and dependencies
2. Pick a driver for a particular db
import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession
3. Describe the Database schema
object Coffees extends Table[(String, Double)]("COFFEES"){
def name = column[String]("COF_NAME", O.PrimaryKey)
def price = column[Double]("PRICE")
def * = name ~ price
}
4. Write queries
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
Coffees.filter(_.price < 10.0).map(_.name).list
}
Dependencies
I will just make this example happen on my easy spray project.
"com.typesafe" % "slick_2.10.0-RC2" % "0.11.2",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.h2database" % "h2" % "1.3.170",
"org.xerial" % "sqlite-jdbc" % "3.6.20",
"mysql" % "mysql-connector-java" % "5.1.13"
/*
"org.apache.derby" % "derby" % "10.6.1.0",
"org.hsqldb" % "hsqldb" % "2.0.0",
"postgresql" % "postgresql" % "8.4-701.jdbc4",
"mysql" % "mysql-connector-java" % "5.1.13"
*/
Imports
Take the example in project slick-examples/src/main/scala/scala.slick.examples.lifted.FirstExample
And make sure we do not use the master, we need to use the tag branch 0.11.2.
// Use H2Driver to connect to an H2 database
import scala.slick.driver.H2Driver.simple._
// Use the implicit threadLocalSession
import Database.threadLocalSession
Database Connection
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
…snip…
}
Schema Definition with Forekey
object Suppliers extends Table[(Int, String, String, String, String, String)]("SUPPLIERS") {
def id = column[Int]("SUP_ID", O.PrimaryKey) // 1 This is the primary key column
def name = column[String]("SUP_NAME") // 2
def street = column[String]("STREET") //3
def city = column[String]("CITY") //4
def state = column[String]("STATE") //5
def zip = column[String]("ZIP") // 6
def * = id ~ name ~ street ~ city ~ state ~ zip
}
object Coffees extends Table[(String, Int, Double, Int, Int)]("COFFEES") {
def name = column[String]("COF_NAME", O.PrimaryKey) //1
def supID = column[Int]("SUP_ID") //2
def price = column[Double]("PRICE") //3
def sales = column[Int]("SALES") //4
def total = column[Int]("TOTAL") //5
def * = name ~ supID ~ price ~ sales ~ total
def supplier = foreignKey("SUP_FK", supID, Suppliers)(_.id)
}
Populating the Database
Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") withSession {
(Suppliers.ddl ++ Coffees.ddl).create
Suppliers.insert(1, "Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
Suppliers.insert(2, "Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460")
Suppliers.insert(3, "The High Ground", "100 Coffee Lane", "Meadows", "CA", "93966")
Coffees.insertAll(
("Colombian", 1, 7.99, 0, 0),
("French_Roast", 3, 8.99, 0, 0),
("Espresso", 2, 9.99, 0, 0),
("Colombian_Decaf", 2, 8.99, 0, 0),
("French_Roast_Decaf", 1, 9.99, 0, 0))
}
Querying
Query(TableName) foreach show up all the data in one table
println("Coffees:")
Query(Coffees) foreach {
case (name, supID, price, sales, total) =>
println(" " + name + "\t" + supID + "\t" + price + "\t" + sales + "\t" + total)
}
println("Manual join:")
val q2 = for {
c <- Coffees if c.price < 9.0 //table 1 with price condition
s <- Suppliers if s.id === c.supID //table 2 with join id
} yield (c.name, s.name)
for (t <- q2) println(" " + t._1 + " supplied by " + t._2)
println("Join by foreign key:")
val q3 = for {
c <- Coffees if c.price < 9.0
s <- c.supplier
} yield (c.name, s.name)
// This time we read the result set into a List
val l3: List[(String, String)] = q3.list
for ((s1, s2) <- l3) println(" " + s1 + " supplied by " + s2)
println(q3.selectStatement)
select x2."COF_NAME", x3."SUP_NAME" from "COFFEES" x2, "SUPPLIERS" x3 where (x2."PRICE" < 9.0) and (x3."SUP_ID" = x2."SUP_ID")
References:
http://slick.typesafe.com/
http://slick.typesafe.com/docs/
http://slick.typesafe.com/doc/0.11.2/
http://slick.typesafe.com/doc/0.11.2/gettingstarted.html
发表评论
-
Update Site will come soon
2021-06-02 04:10 1694I am still keep notes my tech n ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 310Hadoop Docker 2019 Version 3.2. ... -
Nginx and Proxy 2019(1)Nginx Enable Lua and Parse JSON
2019-12-03 04:17 472Nginx and Proxy 2019(1)Nginx En ... -
Data Solution 2019(13)Docker Zeppelin Notebook and Memory Configuration
2019-11-09 07:15 316Data Solution 2019(13)Docker Ze ... -
Data Solution 2019(10)Spark Cluster Solution with Zeppelin
2019-10-29 08:37 265Data Solution 2019(10)Spark Clu ... -
AMAZON Kinesis Firehose 2019(1)Firehose Buffer to S3
2019-10-01 10:15 341AMAZON Kinesis Firehose 2019(1) ... -
Rancher and k8s 2019(3)Clean Installation on CentOS7
2019-09-19 23:25 336Rancher and k8s 2019(3)Clean In ... -
Pacemaker 2019(1)Introduction and Installation on CentOS7
2019-09-11 05:48 360Pacemaker 2019(1)Introduction a ... -
Crontab-UI installation and Introduction
2019-08-30 05:54 472Crontab-UI installation and Int ... -
Spiderkeeper 2019(1)Installation and Introduction
2019-08-29 06:49 534Spiderkeeper 2019(1)Installatio ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 387Supervisor 2019(2)Ubuntu and Mu ... -
Supervisor 2019(1)CentOS 7
2019-08-19 09:33 343Supervisor 2019(1)CentOS 7 Ins ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 384Redis Cluster 2019(3)Redis Clus ... -
Amazon Lambda and Version Limit
2019-08-02 01:42 450Amazon Lambda and Version Limit ... -
MySQL HA Solution 2019(1)Master Slave on MySQL 5.7
2019-07-27 22:26 551MySQL HA Solution 2019(1)Master ... -
RabbitMQ Cluster 2019(2)Cluster HA and Proxy
2019-07-11 12:41 475RabbitMQ Cluster 2019(2)Cluster ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:35 334Running Zeppelin with Nginx Aut ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:34 335Running Zeppelin with Nginx Aut ... -
ElasticSearch(3)Version Upgrade and Cluster
2019-05-20 05:00 340ElasticSearch(3)Version Upgrade ... -
Jetty Server and Cookie Domain Name
2019-04-28 23:59 420Jetty Server and Cookie Domain ...
相关推荐
SlickGrid-master-2013-1-1 SlickGrid-master-2013-1-1 SlickGrid-master-2013-1-1 SlickGrid-master-2013-1-1
Transitioning from programming to game development can often be difficult, however, Slick2D helps developers to create amazing games without having to deal with low level programming, and it ...
<div><img src="image1.jpg" alt="Image 1"> <div><img src="image2.jpg" alt="Image 2"> <div><img src="image3.jpg" alt="Image 3"> ``` 接下来,为了使轮播图生效,需要在页面中引入SLICK插件的CSS和...
《SlickEdit 13.0.0.0 绿色版与SlickEdit 12.0.3汉化包详解》 SlickEdit是一款备受程序员喜爱的文本编辑器,以其强大的功能和高效的代码编辑体验闻名。在这个压缩包中,我们得到了两个版本的SlickEdit:13.0.0.0的...
《SlickEdit v27 Linux 64 专业版:高效编程的新篇章》 SlickEdit v27 是一款专为Linux 64位操作系统设计的专业级代码编辑器,它以其强大的功能和高效的编程体验而备受程序员的青睐。在这款软件中,开发者可以享受...
《Slick:最佳轮播插件的深度解析》 在网页设计中,轮播图(Carousel)是一种常见的展示方式,它能有效地利用有限的空间展示多张图片或内容。本文将聚焦于一款被誉为“感觉最好用”的轮播插件——Slick,通过分析其...
1. **多列布局**:Slick支持多列布局,可以在同一幻灯片组件中展示多个并排的项目,非常适合用于商品展示或横向滚动的新闻模块。 2. **自适应设计**:插件能够自动适应不同设备和屏幕尺寸,提供良好的响应式体验,...
Slickedit2014 Linux64 Part1 (带破解)不解释
根据提供的信息,我们可以总结出以下相关知识点,这些知识点主要聚焦于"Slick-3"这一数据库访问库的基础使用方法以及如何通过Scala语言进行高效的数据查询与操作。 ### Slick-3 简介 Slick-3 是一个用于 Scala 的...
slick.min.js
SlickGrid API SlickGrid 是一个功能强大且灵活的网格控件库,旨在提供一个高效、可扩展、可定制的数据网格控件解决方案。下面是 SlickGrid API 的详细知识点: Constructor Slick.Grid 构造函数是 SlickGrid 的...
1. **界面定制**:首先,你可以调整Slick Edit的界面布局,使其适应个人工作习惯。这包括改变窗口大小、排列方式,甚至自定义快捷键,以实现快速访问常用功能。 2. **字体与颜色设置**:为了减轻眼睛疲劳,可以在...
1. 隐藏某个大括号内的内容 SlickEdit 提供了隐藏大括号内的内容的功能,这可以帮助开发者快速隐藏不需要的代码。操作步骤为:将光标放到所需隐藏的大括号内的任意位置,然后选择菜单 View-> Hide Code Block。 2....
《SlickGrid:构建高效Web表格的神器》 SlickGrid,这个名为"SlickGrid-master"的项目,是一个专门用于Web应用的表格控件,它以其简洁、快速和灵活的特性,深受开发者们的喜爱。在网页开发中,尤其是在处理大量数据...
1. **完全响应式**:Slick支持不同设备的屏幕尺寸,能自动适应手机、平板电脑和桌面电脑等不同设备。 2. **自定义设置**:开发者可以调整滑动速度、自动播放间隔、是否显示分页导航、左右箭头以及更多其他选项,以...
1. **高性能**:SlickGrid采用虚拟滚动技术,只渲染当前屏幕可见的数据行,大大提高了在大数据集下的页面加载速度和滚动流畅度。 2. **自定义列和表头**:用户可以根据需求自由定义列的宽度、排序方式、过滤条件...
1. **特性与优势** - **高性能**:SlickGrid通过虚拟滚动技术实现高效渲染,只在可视区域内渲染行,避免了内存占用过大和页面卡顿的问题。 - **高度可定制**:它提供了丰富的API和插件系统,允许开发者根据需求...
解压方法step 1三个文件合成一个cat slickedit_linux_32bit.tar.gz.a* >slickedit.tar.gz step 2 tar xzvf slickedit.tar.gz slickedit 2014 v19 linux 32位版的 已经和谐了,step1:解压后执行vsinst安装,安装过程...
《使用SlickEdit调用MDK进行嵌入式系统开发详解》 在嵌入式系统开发领域,高效而精准的代码编辑与编译工具至关重要。SlickEdit是一款强大的多平台文本编辑器,它以其丰富的特性集和高度自定义性赢得了程序员的青睐...
1. **数据模型**: Slick允许我们用Scala的类和对象来定义数据模型,这些类和对象对应数据库中的表和字段。例如,我们可以创建一个`User`类来代表用户表,并通过`Table`抽象类来映射数据库表结构。 ```scala case ...