- 浏览: 2488849 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 1613I am still keep notes my tech n ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 259Hadoop Docker 2019 Version 3.2. ... -
Nginx and Proxy 2019(1)Nginx Enable Lua and Parse JSON
2019-12-03 04:17 378Nginx and Proxy 2019(1)Nginx En ... -
Data Solution 2019(13)Docker Zeppelin Notebook and Memory Configuration
2019-11-09 07:15 242Data Solution 2019(13)Docker Ze ... -
Data Solution 2019(10)Spark Cluster Solution with Zeppelin
2019-10-29 08:37 211Data Solution 2019(10)Spark Clu ... -
AMAZON Kinesis Firehose 2019(1)Firehose Buffer to S3
2019-10-01 10:15 287AMAZON Kinesis Firehose 2019(1) ... -
Rancher and k8s 2019(3)Clean Installation on CentOS7
2019-09-19 23:25 264Rancher and k8s 2019(3)Clean In ... -
Pacemaker 2019(1)Introduction and Installation on CentOS7
2019-09-11 05:48 302Pacemaker 2019(1)Introduction a ... -
Crontab-UI installation and Introduction
2019-08-30 05:54 411Crontab-UI installation and Int ... -
Spiderkeeper 2019(1)Installation and Introduction
2019-08-29 06:49 460Spiderkeeper 2019(1)Installatio ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 323Supervisor 2019(2)Ubuntu and Mu ... -
Supervisor 2019(1)CentOS 7
2019-08-19 09:33 289Supervisor 2019(1)CentOS 7 Ins ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 336Redis Cluster 2019(3)Redis Clus ... -
Amazon Lambda and Version Limit
2019-08-02 01:42 392Amazon Lambda and Version Limit ... -
MySQL HA Solution 2019(1)Master Slave on MySQL 5.7
2019-07-27 22:26 417MySQL HA Solution 2019(1)Master ... -
RabbitMQ Cluster 2019(2)Cluster HA and Proxy
2019-07-11 12:41 420RabbitMQ Cluster 2019(2)Cluster ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:35 292Running Zeppelin with Nginx Aut ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:34 299Running Zeppelin with Nginx Aut ... -
ElasticSearch(3)Version Upgrade and Cluster
2019-05-20 05:00 295ElasticSearch(3)Version Upgrade ... -
Jetty Server and Cookie Domain Name
2019-04-28 23:59 363Jetty 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 ...
Slickedit2014 Linux64 Part1 (带破解)不解释
slick.min.js
解压方法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 Linux 16.0.3.0.7z.001卷1
essential-slick-3
File Version: 1, 0, 0, 1 Modified: 2012-06-14, 17:15:51 MD5: DE588FD0A7F723CD6881A5DBFE4D55D8 SHA1: 35A9B4E851B6747088564E97CD739D86828346B6 CRC32: B5D27155 -- If Euclid failed to kindle your ...
解压方法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安装,安装过程...
Slickedit2013 Linux64 Part1 (带破解)
开源的WEB表格控件 SlickGrid
slickedit 16.0.3 linux 32 位 破解程序 在网上找了半天没找到我要的版本,只好自己改一个了 解压后直接将 vs 覆盖 /opt/slickedit/bin 目录下的vs即可
文档里整理了slickedit使用四年多来的技巧和相关设置。
SlickEdit17.08 for linux64 的破解文件和slickedit的安装说明及破解说明
slickedit 16.0.0.3 绿色 破解版,自己做的,非常方便,运行.\config\start_slickedit16.bat即可,生成的配置也在.\config下
slickedit_16.0.2破解文件for Linux
解压方法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 v27 linux 64 专业版
传说最好用的编辑器。目前最新版本,上来更新一下。一共是2个压缩文件,用7ZIP压缩。都下完以后放在同目录下,改成同文件名即可。...例:第一个文件的文件名为 SlickEdit 13.0.0.7z.001 ,SlickEdit 13.0.0就是文件名。
slickedit 2016 21版本 破解补丁,有详细说明(360会有XX提示)。