SlideShare a Scribd company logo
Statement Fragments
- How to write dynamic SQL queries in doobie -
2017-01-28
第十八回 #渋谷java
0.4.0 release!
● Cats Support
● Simple statement logging Support
● Changes to Add-On Modules
● Dynamic SQL
0.4.0 release!
● Cats Support
● Simple statement logging Support
● Changes to Add-On Modules
● Dynamic SQL
The dynamic SQL story
The dynamic SQL story is now slightly better with
the introduction of composable statement
fragments.
"Changes to Core". changelog.
https://github.com/tpolecat/doobie/blob/series/0.4.x/CHANGELOG.md#changes-to-core, (参照 2017-01-25)
The dynamic SQL story
The dynamic SQL story is now slightly better with
the introduction of composable statement
fragments.
"Changes to Core". changelog.
https://github.com/tpolecat/doobie/blob/series/0.4.x/CHANGELOG.md#changes-to-core, (参照 2017-01-25)
若干改善された
Setting Up
import doobie.imports._
import scalaz._, Scalaz._, concurrent.Task
val xa = DriverManagerTransactor[Task](
"org.h2.Driver", "url", "user", "password"
)
// YOLO mode
import xa.yolo._
SQL literals
val select = fr"select * from user"
val where = fr"where uid = $id"
val sql = select ++ where
sql.query[User].quick.unsafePerformSync
SQL literals
val select: Fragment = fr"select * from user"
val where: Fragment = fr"where uid = $id"
val sql: Fragment = select ++ where
sql.query[User].quick.unsafePerformSync
sqlの代わりにfrで定義
SQL literals
val select: Fragment = fr"select * from user"
val where: Fragment = fr"where uid = $id"
val sql: Fragment = select ++ where
sql.query[User].quick.unsafePerformSync
++で連結
An arbitrary string value
val table = "user"
val select = fr"select * from"
val sql = select ++ Fragment.const(table)
sql.query[Unit].sql
// "select * from user"
An arbitrary string value
val table = "user"
val select = fr"select * from"
val sql = select ++ Fragment.const(table)
sql.query[Unit].sql
// "select * from user"
SQLパラメータではないもの
The Fragments Module
● some convenience combinators
○ andOpt
○ orOpt
○ whereAndOpt
○ whereOrOpt
○ in
and so on
The Fragments Module - whereAndOpt
import Fragments._
val uid: Option[Int] = ...
val json: Option[String] = ...
val sql = fr"select * from user" ++
whereAndOpt(
uid.map(p => fr"uid = $p"), // Option[Fragment]
json.map(p => fr"json like $p") // Option[Fragment]
)
The Fragments Module - whereAndOpt
import Fragments._
val uid: Option[Int] = None
val json: Option[String] = None
val sql = fr"select * from user" ++
whereAndOpt(
uid.map(p => fr"uid = $p"), // Option[Fragment]
json.map(p => fr"json like $p") // Option[Fragment]
)
// "select * from user "
The Fragments Module - whereAndOpt
import Fragments._
val uid: Option[Int] = Some(1)
val json: Option[String] = None
val sql = fr"select * from user" ++
whereAndOpt(
uid.map(p => fr"uid = $p"), // Option[Fragment]
json.map(p => fr"json like $p") // Option[Fragment]
)
// "select * from user WHERE uid = ? "
The Fragments Module - whereAndOpt
import Fragments._
val uid: Option[Int] = Some(1)
val json: Option[String] = Some("%foo%")
val sql = fr"select * from user" ++
whereAndOpt(
uid.map(p => fr"uid = $p"), // Option[Fragment]
json.map(p => fr"json like $p") // Option[Fragment]
)
// "select * from user WHERE uid = ? AND json like ? "
The Fragments Module - in
import Fragments._
val uids: List[Int] = ...
val sql = fr"select * from user" ++
whereAndOpt(
uids.toNel.map(p => in(fr"uid", p))// Option[Fragment]
)
Option[NonEmptyList[Int]]
The Fragments Module - in
import Fragments._
val uids: List[Int] = Nil
val sql = fr"select * from user" ++
whereAndOpt(
uids.toNel.map(p => in(fr"uid", p))// Option[Fragment]
)
// "select * from user "
The Fragments Module - in
import Fragments._
val uids: List[Int] = List(1,10)
val sql = fr"select * from user" ++
whereAndOpt(
uids.toNel.map(p => in(fr"uid", p))// Option[Fragment]
)
// "select * from user WHERE uid IN (?, ?) "
Conclusion
● 嬉しいこと
○ dynamic SQL が書けるようになった
○ 特にwhere句の組み立ては高確率で必要になる
● 悲しいこと
○ 「若干」感
○ 使い方がよくわからないもの(andOpt)
まだ0.4.xなのでこれからの進化に期待!

More Related Content

What's hot

ドキュメントを作りたくなってしまう魔法のツールSphinx
ドキュメントを作りたくなってしまう魔法のツールSphinxドキュメントを作りたくなってしまう魔法のツールSphinx
ドキュメントを作りたくなってしまう魔法のツールSphinx
Takayuki Shimizukawa
 
Datadog による Container の監視について
Datadog による Container の監視についてDatadog による Container の監視について
Datadog による Container の監視について
Masaya Aoyama
 
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
FIDO Alliance
 
Riverpodでテストを書こう
Riverpodでテストを書こうRiverpodでテストを書こう
Riverpodでテストを書こう
Shinnosuke Tokuda
 
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forestMutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
Jun Kurihara
 
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
Salesforce Developers Japan
 
Azureをフル活用したサーバーレスの潮流について
Azureをフル活用したサーバーレスの潮流についてAzureをフル活用したサーバーレスの潮流について
Azureをフル活用したサーバーレスの潮流について
真吾 吉田
 
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのか
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのかDeveloper's summit 2021 [19-D-5]なぜ今、ローコードなのか
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのか
Tetsuo Ajima
 
Project calico introduction - OpenStack最新情報セミナー 2017年7月
Project calico introduction - OpenStack最新情報セミナー 2017年7月Project calico introduction - OpenStack最新情報セミナー 2017年7月
Project calico introduction - OpenStack最新情報セミナー 2017年7月
VirtualTech Japan Inc.
 
PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門
泰 増田
 
Sec013 その資格情報、簡
Sec013 その資格情報、簡Sec013 その資格情報、簡
Sec013 その資格情報、簡
Tech Summit 2016
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッションEnpel
 
CVE-2021-3156 Baron samedit (sudoの脆弱性)
CVE-2021-3156 Baron samedit (sudoの脆弱性)CVE-2021-3156 Baron samedit (sudoの脆弱性)
CVE-2021-3156 Baron samedit (sudoの脆弱性)
Tetsuya Hasegawa
 
NGINXをBFF (Backend for Frontend)として利用した話
NGINXをBFF (Backend for Frontend)として利用した話NGINXをBFF (Backend for Frontend)として利用した話
NGINXをBFF (Backend for Frontend)として利用した話
Hitachi, Ltd. OSS Solution Center.
 
ざっくり解説 LINE ログイン
ざっくり解説 LINE ログインざっくり解説 LINE ログイン
ざっくり解説 LINE ログイン
Naohiro Fujie
 
Air事業のデザイン組織とデザイナー
Air事業のデザイン組織とデザイナーAir事業のデザイン組織とデザイナー
Air事業のデザイン組織とデザイナー
Recruit Lifestyle Co., Ltd.
 
Data Factoryの勘所・大事なところ
Data Factoryの勘所・大事なところData Factoryの勘所・大事なところ
Data Factoryの勘所・大事なところ
Tsubasa Yoshino
 
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~Tatsuo Kudo
 
これからのネイティブアプリにおけるOpenID Connectの活用
これからのネイティブアプリにおけるOpenID Connectの活用これからのネイティブアプリにおけるOpenID Connectの活用
これからのネイティブアプリにおけるOpenID Connectの活用
Masaru Kurahayashi
 
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
Recruit Technologies
 

What's hot (20)

ドキュメントを作りたくなってしまう魔法のツールSphinx
ドキュメントを作りたくなってしまう魔法のツールSphinxドキュメントを作りたくなってしまう魔法のツールSphinx
ドキュメントを作りたくなってしまう魔法のツールSphinx
 
Datadog による Container の監視について
Datadog による Container の監視についてDatadog による Container の監視について
Datadog による Container の監視について
 
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
パスワードのいらない世界へ~NTTドコモにおけるFIDO認証導入事例とエコシステムへの貢献
 
Riverpodでテストを書こう
Riverpodでテストを書こうRiverpodでテストを書こう
Riverpodでテストを書こう
 
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forestMutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
Mutualized Oblivious DNS (μODNS): Hiding a tree in the wild forest
 
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
モダンなイベント駆動型システム連携を学ぼう〜Platform Events 入門
 
Azureをフル活用したサーバーレスの潮流について
Azureをフル活用したサーバーレスの潮流についてAzureをフル活用したサーバーレスの潮流について
Azureをフル活用したサーバーレスの潮流について
 
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのか
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのかDeveloper's summit 2021 [19-D-5]なぜ今、ローコードなのか
Developer's summit 2021 [19-D-5]なぜ今、ローコードなのか
 
Project calico introduction - OpenStack最新情報セミナー 2017年7月
Project calico introduction - OpenStack最新情報セミナー 2017年7月Project calico introduction - OpenStack最新情報セミナー 2017年7月
Project calico introduction - OpenStack最新情報セミナー 2017年7月
 
PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門PlaySQLAlchemy: SQLAlchemy入門
PlaySQLAlchemy: SQLAlchemy入門
 
Sec013 その資格情報、簡
Sec013 その資格情報、簡Sec013 その資格情報、簡
Sec013 その資格情報、簡
 
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション
2 TomcatによるWebアプリケーションサーバ構築 第2章 Tomcat概要(2)-セッション
 
CVE-2021-3156 Baron samedit (sudoの脆弱性)
CVE-2021-3156 Baron samedit (sudoの脆弱性)CVE-2021-3156 Baron samedit (sudoの脆弱性)
CVE-2021-3156 Baron samedit (sudoの脆弱性)
 
NGINXをBFF (Backend for Frontend)として利用した話
NGINXをBFF (Backend for Frontend)として利用した話NGINXをBFF (Backend for Frontend)として利用した話
NGINXをBFF (Backend for Frontend)として利用した話
 
ざっくり解説 LINE ログイン
ざっくり解説 LINE ログインざっくり解説 LINE ログイン
ざっくり解説 LINE ログイン
 
Air事業のデザイン組織とデザイナー
Air事業のデザイン組織とデザイナーAir事業のデザイン組織とデザイナー
Air事業のデザイン組織とデザイナー
 
Data Factoryの勘所・大事なところ
Data Factoryの勘所・大事なところData Factoryの勘所・大事なところ
Data Factoryの勘所・大事なところ
 
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
パスワード氾濫時代のID管理とは? ~最新のOpenIDが目指すユーザー認証の効率的な強化~
 
これからのネイティブアプリにおけるOpenID Connectの活用
これからのネイティブアプリにおけるOpenID Connectの活用これからのネイティブアプリにおけるOpenID Connectの活用
これからのネイティブアプリにおけるOpenID Connectの活用
 
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
リクルートにおけるVDI導入 ~働き方変革とセキュリティ向上の両立を目指して~
 

Viewers also liked

Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
chibochibo
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
What is doobie? - database access for scala -
What is doobie? - database access for scala -What is doobie? - database access for scala -
What is doobie? - database access for scala -
chibochibo
 
ビッグじゃなくても使えるSpark Streaming
ビッグじゃなくても使えるSpark Streamingビッグじゃなくても使えるSpark Streaming
ビッグじゃなくても使えるSpark Streaming
chibochibo
 
今から始める Lens/Prism
今から始める Lens/Prism今から始める Lens/Prism
今から始める Lens/Prism
Naoki Aoyama
 
マイクロサービスバックエンドAPIのためのRESTとgRPC
マイクロサービスバックエンドAPIのためのRESTとgRPCマイクロサービスバックエンドAPIのためのRESTとgRPC
マイクロサービスバックエンドAPIのためのRESTとgRPC
disc99_
 
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 SpringGoでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Yahoo!デベロッパーネットワーク
 
Sql
SqlSql
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Quartzでcronを範囲検索したい
Quartzでcronを範囲検索したいQuartzでcronを範囲検索したい
Quartzでcronを範囲検索したい
chibochibo
 
テストゼロからイチに進むための戦略と戦術
テストゼロからイチに進むための戦略と戦術テストゼロからイチに進むための戦略と戦術
テストゼロからイチに進むための戦略と戦術
Y Watanabe
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
Myungjin Lee
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
Vaibhav0
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
rehaniltifat
 
Why Outsourcing Graphic Design Projects is the Next Big Thing?
Why Outsourcing Graphic Design Projects is the Next Big Thing?Why Outsourcing Graphic Design Projects is the Next Big Thing?
Why Outsourcing Graphic Design Projects is the Next Big Thing?
Rahul Aggarwal
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business Statistics
Atiq Rehman
 
Arquitectura barroca
Arquitectura barrocaArquitectura barroca
Arquitectura barroca
Maria Carmona
 
sbtマルチプロジェクトビルドの使いどころ
sbtマルチプロジェクトビルドの使いどころsbtマルチプロジェクトビルドの使いどころ
sbtマルチプロジェクトビルドの使いどころ
Kazuhiro Hara
 
究極のPHP本完成
究極のPHP本完成究極のPHP本完成
究極のPHP本完成
Katsuhiro Ogawa
 
20160902 scalaの魅力を話してみる
20160902 scalaの魅力を話してみる20160902 scalaの魅力を話してみる
20160902 scalaの魅力を話してみる
Yoshitaka Fujii
 

Viewers also liked (20)

Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
What is doobie? - database access for scala -
What is doobie? - database access for scala -What is doobie? - database access for scala -
What is doobie? - database access for scala -
 
ビッグじゃなくても使えるSpark Streaming
ビッグじゃなくても使えるSpark Streamingビッグじゃなくても使えるSpark Streaming
ビッグじゃなくても使えるSpark Streaming
 
今から始める Lens/Prism
今から始める Lens/Prism今から始める Lens/Prism
今から始める Lens/Prism
 
マイクロサービスバックエンドAPIのためのRESTとgRPC
マイクロサービスバックエンドAPIのためのRESTとgRPCマイクロサービスバックエンドAPIのためのRESTとgRPC
マイクロサービスバックエンドAPIのためのRESTとgRPC
 
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 SpringGoでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
Goでヤフーの分散オブジェクトストレージを作った話 Go Conference 2017 Spring
 
Sql
SqlSql
Sql
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Quartzでcronを範囲検索したい
Quartzでcronを範囲検索したいQuartzでcronを範囲検索したい
Quartzでcronを範囲検索したい
 
テストゼロからイチに進むための戦略と戦術
テストゼロからイチに進むための戦略と戦術テストゼロからイチに進むための戦略と戦術
テストゼロからイチに進むための戦略と戦術
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
 
Why Outsourcing Graphic Design Projects is the Next Big Thing?
Why Outsourcing Graphic Design Projects is the Next Big Thing?Why Outsourcing Graphic Design Projects is the Next Big Thing?
Why Outsourcing Graphic Design Projects is the Next Big Thing?
 
Introduction to Business Statistics
Introduction to Business StatisticsIntroduction to Business Statistics
Introduction to Business Statistics
 
Arquitectura barroca
Arquitectura barrocaArquitectura barroca
Arquitectura barroca
 
sbtマルチプロジェクトビルドの使いどころ
sbtマルチプロジェクトビルドの使いどころsbtマルチプロジェクトビルドの使いどころ
sbtマルチプロジェクトビルドの使いどころ
 
究極のPHP本完成
究極のPHP本完成究極のPHP本完成
究極のPHP本完成
 
20160902 scalaの魅力を話してみる
20160902 scalaの魅力を話してみる20160902 scalaの魅力を話してみる
20160902 scalaの魅力を話してみる
 

Similar to Dynamic SQL in doobie

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
The MEAN stack
The MEAN stack The MEAN stack
The MEAN stack
Nattaya Mairittha
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
Eugenio Minardi
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the Cloud
James Thomas
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
Matthew Clarke
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
Kamil Augustynowicz
 
Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
Cheng-Yi Yu
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
Filippo Matteo Riggio
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Alek Davis
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
Jasper Moelker
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
Felix Gessert
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
Alfonso Fernández
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
ChengHui Weng
 
Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburg
Baqend
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
njbartlett
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstream
Steve Lee
 

Similar to Dynamic SQL in doobie (20)

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 
The MEAN stack
The MEAN stack The MEAN stack
The MEAN stack
 
Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)Web automation with #d8rules (European Drupal Days 2015)
Web automation with #d8rules (European Drupal Days 2015)
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the Cloud
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
 
Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Voorhoede - Front-end architecture
Voorhoede - Front-end architectureVoorhoede - Front-end architecture
Voorhoede - Front-end architecture
 
Building an Angular 2 App
Building an Angular 2 AppBuilding an Angular 2 App
Building an Angular 2 App
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
 
Angular 2 at solutions.hamburg
Angular 2 at solutions.hamburgAngular 2 at solutions.hamburg
Angular 2 at solutions.hamburg
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
 
Getting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstreamGetting Reactive with Cycle.js and xstream
Getting Reactive with Cycle.js and xstream
 

More from chibochibo

Tour of Apache PredictionIO in 10 Minutes
Tour of Apache PredictionIO in 10 MinutesTour of Apache PredictionIO in 10 Minutes
Tour of Apache PredictionIO in 10 Minutes
chibochibo
 
Crawler Commons
Crawler CommonsCrawler Commons
Crawler Commons
chibochibo
 
LocalStack
LocalStackLocalStack
LocalStack
chibochibo
 
Is spark streaming based on reactive streams?
Is spark streaming based on reactive streams?Is spark streaming based on reactive streams?
Is spark streaming based on reactive streams?
chibochibo
 
nioで作ったBufferedWriterに変えたら例外になった
nioで作ったBufferedWriterに変えたら例外になったnioで作ったBufferedWriterに変えたら例外になった
nioで作ったBufferedWriterに変えたら例外になった
chibochibo
 
Spark Streaming on AWS -S3からKinesisへ-
Spark Streaming on AWS -S3からKinesisへ-Spark Streaming on AWS -S3からKinesisへ-
Spark Streaming on AWS -S3からKinesisへ-
chibochibo
 
Spark in small or middle scale data processing with Elasticsearch
Spark in small or middle scale data processing with ElasticsearchSpark in small or middle scale data processing with Elasticsearch
Spark in small or middle scale data processing with Elasticsearchchibochibo
 
What's a macro?: Learning by Examples
What's a macro?: Learning by ExamplesWhat's a macro?: Learning by Examples
What's a macro?: Learning by Examples
chibochibo
 
Spring Boot Introduction
Spring Boot IntroductionSpring Boot Introduction
Spring Boot Introduction
chibochibo
 

More from chibochibo (10)

Tour of Apache PredictionIO in 10 Minutes
Tour of Apache PredictionIO in 10 MinutesTour of Apache PredictionIO in 10 Minutes
Tour of Apache PredictionIO in 10 Minutes
 
Crawler Commons
Crawler CommonsCrawler Commons
Crawler Commons
 
LocalStack
LocalStackLocalStack
LocalStack
 
Is spark streaming based on reactive streams?
Is spark streaming based on reactive streams?Is spark streaming based on reactive streams?
Is spark streaming based on reactive streams?
 
nioで作ったBufferedWriterに変えたら例外になった
nioで作ったBufferedWriterに変えたら例外になったnioで作ったBufferedWriterに変えたら例外になった
nioで作ったBufferedWriterに変えたら例外になった
 
Spark Streaming on AWS -S3からKinesisへ-
Spark Streaming on AWS -S3からKinesisへ-Spark Streaming on AWS -S3からKinesisへ-
Spark Streaming on AWS -S3からKinesisへ-
 
Spark in small or middle scale data processing with Elasticsearch
Spark in small or middle scale data processing with ElasticsearchSpark in small or middle scale data processing with Elasticsearch
Spark in small or middle scale data processing with Elasticsearch
 
What's a macro?: Learning by Examples
What's a macro?: Learning by ExamplesWhat's a macro?: Learning by Examples
What's a macro?: Learning by Examples
 
Spring Boot Introduction
Spring Boot IntroductionSpring Boot Introduction
Spring Boot Introduction
 
Slick入門
Slick入門Slick入門
Slick入門
 

Recently uploaded

Prsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptxPrsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptx
prafulpawar29
 
Disaster Management project for holidays homework and other uses
Disaster Management project for holidays homework and other usesDisaster Management project for holidays homework and other uses
Disaster Management project for holidays homework and other uses
RIDHIMAGARG21
 
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdfWhy Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
Ben Linders
 
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
OECD Directorate for Financial and Enterprise Affairs
 
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
OECD Directorate for Financial and Enterprise Affairs
 
Gamify it until you make it Improving Agile Development and Operations with ...
Gamify it until you make it  Improving Agile Development and Operations with ...Gamify it until you make it  Improving Agile Development and Operations with ...
Gamify it until you make it Improving Agile Development and Operations with ...
Ben Linders
 
Using-Presentation-Software-to-the-Fullf.pptx
Using-Presentation-Software-to-the-Fullf.pptxUsing-Presentation-Software-to-the-Fullf.pptx
Using-Presentation-Software-to-the-Fullf.pptx
kainatfatyma9
 
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
gfysze
 
IEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdfIEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdf
Claudio Gallicchio
 
Genesis chapter 3 Isaiah Scudder.pptx
Genesis    chapter 3 Isaiah Scudder.pptxGenesis    chapter 3 Isaiah Scudder.pptx
Genesis chapter 3 Isaiah Scudder.pptx
FamilyWorshipCenterD
 
Legislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptxLegislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptx
Charmi13
 
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates
UAE Ppt
 
Proposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP IncProposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP Inc
Raheem Muhammad
 
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
SkillCertProExams
 
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPEACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
Charmi13
 
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
OECD Directorate for Financial and Enterprise Affairs
 
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
kekzed
 
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdfBRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
Robin Haunschild
 

Recently uploaded (19)

Prsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptxPrsentation for VIVA Welike project 1semester.pptx
Prsentation for VIVA Welike project 1semester.pptx
 
Disaster Management project for holidays homework and other uses
Disaster Management project for holidays homework and other usesDisaster Management project for holidays homework and other uses
Disaster Management project for holidays homework and other uses
 
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdfWhy Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
Why Psychological Safety Matters for Software Teams - ACE 2024 - Ben Linders.pdf
 
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
The Intersection between Competition and Data Privacy – OECD – June 2024 OECD...
 
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
The Intersection between Competition and Data Privacy – COLANGELO – June 2024...
 
Gamify it until you make it Improving Agile Development and Operations with ...
Gamify it until you make it  Improving Agile Development and Operations with ...Gamify it until you make it  Improving Agile Development and Operations with ...
Gamify it until you make it Improving Agile Development and Operations with ...
 
Using-Presentation-Software-to-the-Fullf.pptx
Using-Presentation-Software-to-the-Fullf.pptxUsing-Presentation-Software-to-the-Fullf.pptx
Using-Presentation-Software-to-the-Fullf.pptx
 
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
一比一原版(unc毕业证书)美国北卡罗来纳大学教堂山分校毕业证如何办理
 
IEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdfIEEE CIS Webinar Sustainable futures.pdf
IEEE CIS Webinar Sustainable futures.pdf
 
Genesis chapter 3 Isaiah Scudder.pptx
Genesis    chapter 3 Isaiah Scudder.pptxGenesis    chapter 3 Isaiah Scudder.pptx
Genesis chapter 3 Isaiah Scudder.pptx
 
Legislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptxLegislation And Regulations For Import, Manufacture,.pptx
Legislation And Regulations For Import, Manufacture,.pptx
 
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
The Intersection between Competition and Data Privacy – CAPEL – June 2024 OEC...
 
2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates2 December UAE National Day - United Arab Emirates
2 December UAE National Day - United Arab Emirates
 
Proposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP IncProposal: The Ark Project and The BEEP Inc
Proposal: The Ark Project and The BEEP Inc
 
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
ServiceNow CIS-ITSM Exam Dumps & Questions [2024]
 
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPEACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
ACTIVE IMPLANTABLE MEDICAL DEVICE IN EUROPE
 
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
The Intersection between Competition and Data Privacy – KEMP – June 2024 OECD...
 
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
怎么办理(lincoln学位证书)英国林肯大学毕业证文凭学位证书原版一模一样
 
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdfBRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
BRIC_2024_2024-06-06-11:30-haunschild_archival_version.pdf
 

Dynamic SQL in doobie

  • 1. Statement Fragments - How to write dynamic SQL queries in doobie - 2017-01-28 第十八回 #渋谷java
  • 2. 0.4.0 release! ● Cats Support ● Simple statement logging Support ● Changes to Add-On Modules ● Dynamic SQL
  • 3. 0.4.0 release! ● Cats Support ● Simple statement logging Support ● Changes to Add-On Modules ● Dynamic SQL
  • 4. The dynamic SQL story The dynamic SQL story is now slightly better with the introduction of composable statement fragments. "Changes to Core". changelog. https://github.com/tpolecat/doobie/blob/series/0.4.x/CHANGELOG.md#changes-to-core, (参照 2017-01-25)
  • 5. The dynamic SQL story The dynamic SQL story is now slightly better with the introduction of composable statement fragments. "Changes to Core". changelog. https://github.com/tpolecat/doobie/blob/series/0.4.x/CHANGELOG.md#changes-to-core, (参照 2017-01-25) 若干改善された
  • 6. Setting Up import doobie.imports._ import scalaz._, Scalaz._, concurrent.Task val xa = DriverManagerTransactor[Task]( "org.h2.Driver", "url", "user", "password" ) // YOLO mode import xa.yolo._
  • 7. SQL literals val select = fr"select * from user" val where = fr"where uid = $id" val sql = select ++ where sql.query[User].quick.unsafePerformSync
  • 8. SQL literals val select: Fragment = fr"select * from user" val where: Fragment = fr"where uid = $id" val sql: Fragment = select ++ where sql.query[User].quick.unsafePerformSync sqlの代わりにfrで定義
  • 9. SQL literals val select: Fragment = fr"select * from user" val where: Fragment = fr"where uid = $id" val sql: Fragment = select ++ where sql.query[User].quick.unsafePerformSync ++で連結
  • 10. An arbitrary string value val table = "user" val select = fr"select * from" val sql = select ++ Fragment.const(table) sql.query[Unit].sql // "select * from user"
  • 11. An arbitrary string value val table = "user" val select = fr"select * from" val sql = select ++ Fragment.const(table) sql.query[Unit].sql // "select * from user" SQLパラメータではないもの
  • 12. The Fragments Module ● some convenience combinators ○ andOpt ○ orOpt ○ whereAndOpt ○ whereOrOpt ○ in and so on
  • 13. The Fragments Module - whereAndOpt import Fragments._ val uid: Option[Int] = ... val json: Option[String] = ... val sql = fr"select * from user" ++ whereAndOpt( uid.map(p => fr"uid = $p"), // Option[Fragment] json.map(p => fr"json like $p") // Option[Fragment] )
  • 14. The Fragments Module - whereAndOpt import Fragments._ val uid: Option[Int] = None val json: Option[String] = None val sql = fr"select * from user" ++ whereAndOpt( uid.map(p => fr"uid = $p"), // Option[Fragment] json.map(p => fr"json like $p") // Option[Fragment] ) // "select * from user "
  • 15. The Fragments Module - whereAndOpt import Fragments._ val uid: Option[Int] = Some(1) val json: Option[String] = None val sql = fr"select * from user" ++ whereAndOpt( uid.map(p => fr"uid = $p"), // Option[Fragment] json.map(p => fr"json like $p") // Option[Fragment] ) // "select * from user WHERE uid = ? "
  • 16. The Fragments Module - whereAndOpt import Fragments._ val uid: Option[Int] = Some(1) val json: Option[String] = Some("%foo%") val sql = fr"select * from user" ++ whereAndOpt( uid.map(p => fr"uid = $p"), // Option[Fragment] json.map(p => fr"json like $p") // Option[Fragment] ) // "select * from user WHERE uid = ? AND json like ? "
  • 17. The Fragments Module - in import Fragments._ val uids: List[Int] = ... val sql = fr"select * from user" ++ whereAndOpt( uids.toNel.map(p => in(fr"uid", p))// Option[Fragment] ) Option[NonEmptyList[Int]]
  • 18. The Fragments Module - in import Fragments._ val uids: List[Int] = Nil val sql = fr"select * from user" ++ whereAndOpt( uids.toNel.map(p => in(fr"uid", p))// Option[Fragment] ) // "select * from user "
  • 19. The Fragments Module - in import Fragments._ val uids: List[Int] = List(1,10) val sql = fr"select * from user" ++ whereAndOpt( uids.toNel.map(p => in(fr"uid", p))// Option[Fragment] ) // "select * from user WHERE uid IN (?, ?) "
  • 20. Conclusion ● 嬉しいこと ○ dynamic SQL が書けるようになった ○ 特にwhere句の組み立ては高確率で必要になる ● 悲しいこと ○ 「若干」感 ○ 使い方がよくわからないもの(andOpt) まだ0.4.xなのでこれからの進化に期待!