Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Admin site as data
Search
OHTA Shogo
May 30, 2016
Programming
2
590
Admin site as data
Lisp meetup #40の発表資料です。
OHTA Shogo
May 30, 2016
Tweet
Share
More Decks by OHTA Shogo
See All by OHTA Shogo
テンクーでのClojure活用事例
athos
0
270
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
960
kitchen-async: a promising (?) Promise library, or a poor man's core.async
athos
3
400
Clojure 1.9 概要紹介
athos
4
1.4k
ここ最近のClojureScript
athos
5
1.7k
(= ? (+ nREPL Docker))
athos
0
480
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
受け取る人から提供する人になるということ
little_rubyist
0
250
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
最新TCAキャッチアップ
0si43
0
200
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Featured
See All Featured
Code Review Best Practice
trishagee
64
17k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Embracing the Ebb and Flow
colly
84
4.5k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Bash Introduction
62gerente
608
210k
The World Runs on Bad Software
bkeepers
PRO
65
11k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
A designer walks into a library…
pauljervisheath
204
24k
Code Reviewing Like a Champion
maltzj
520
39k
Making Projects Easy
brettharned
115
5.9k
Transcript
"ENJOTJUFBTEBUB Lisp meetup #40 2016/05/30 @athos0220
ཧαΠτͱ
ཧαΠτͱ ‣ 8FCΞϓϦͷཧऀ͚ʹ%#ͷجຊతͳ$36% ૢ࡞ͷΠϯλʔϑΣʔεΛఏڙ͢Δ ‣ ʮཧը໘ʯʮཧϖʔδʯͳͲͱ ‣ %KBOHPͳͲͷ8FCϑϨʔϜϫʔΫϞσϧఆ͔ٛ ΒࣗಈతʹੜͰ͖Δ͜ͱ͕ಛ
యܕతͳߏ ‣ %KBOHP3BJMTɺଟ͘ͷཧ αΠτ03.ͷଘࡏΛԾఆ ‣ 03.͕3%#ͷ$36%ૢ࡞Λ ఏڙ͢Δ ‣ ͞Βʹ03.ͷϞσϧఆ͔ٛΒ ฤूϑΥʔϜΛࣗಈੜ͢Δ
Admin site ORM RDBMS
5IF$MPKVSF8BZ
γϯϓϧ͞ ‣ $MPKVSFͷجຊతཧ೦ͷͻͱͭ ‣ ͭΕͷͳ͍͜ͱ 㱻DPNQMFDU ‣ ͭҎ্ͷͷΛབྷΈ߹ΘͤΔͱෳࡶ ͕͞ੜ͡Δ
‣ γϯϓϧ͞෭࣍తʹಘΒΕΔͷ Ͱͳ͘ɺੵۃతʹબͿͷ
σʔλࢦ ‣ $MPKVSFͰࠐΈσʔλܕΛଟ༻͢Δ ‣ σʔλੜདྷγϯϓϧͰ͋ΓΈ߹ΘͤՄೳ ‣ σʔλʼؔʼϚΫϩͷॱͰΈ߹ΘͤՄೳੑ͕ߴ·Δ ‣ ҆қʹϚΫϩͰ%4-Λ࡞ΔͷͰͳ͘ɺσʔλؔͱ ͯ͠දݱͰ͖ͳ͍͔Λߟ͑Δ
ϑϨʔϜϫʔΫΑΓϥΠϒϥϦ ‣ ϞϊϦγοΫͳϑϨʔϜϫʔΫϑϨʔϜϫʔΫࣗମͷݶ քʹୡͨ͠ͱ͖ͷରॲ͕͍͠ ‣ ୯ػೳͷϥΠϒϥϦΛΈ߹Θͤͯ͏ํ͕ࣗ༝͕ߴ͍ ‣ ͜ͷߟ͔͑Β$MPKVSFʹϑϨʔϜϫʔΫ ಛʹϑϧελοΫ ͳ8"'
͕΄ͱΜͲͳ͍
ʮϑϨʔϜϫʔΫΑΓϥΠϒϥϦʯ ͷ͠͞ ‣ ϥΠϒϥϦಉ࢜ΛΈ߹ΘͤΔͷϢʔβͷͰɺ ͏·͘ڞଘͤ͞ΒΕͳ͍Έ߹Θͤ͋Δ -FJOJOHFOςϯϓϨʔτͰయܕతͳߏΛ࡞ͬͯ͘ΕΔ ͷ͋Δ͕ςϯϓϨʔτࣗମͷอक͕ ‣ ্ͷϨΠϠʔͷϥΠϒϥϦʹͳΔ΄ͲԼͷϨΠϠʔ
ʹͲΜͳϥΠϒϥϦ͕དྷΔ͔Λఆ͖͠Εͳ͍
$MPKVSFʹ͓͚Δ 3%#ϥΠϒϥϦͷมભ
$MPKVSFʹ͓͚Δ 3%#ϥΠϒϥϦͷมભ ‣ 3%#पล$MPKVSFϥΠϒϥϦͷதͰ͕มԽ͠ ͍͢ͷͻͱͭ ‣ େ͖ͳྲྀΕͱͯ͠ΑΓγϯϓϧͳํʹ͔͍ͬͯΔ ,PSNB
)POFZ42- :FTRM)VH42-
,PSNB ςʔϒϧఆٛɺΫΤϦఆٛͷ%4-Λͭ (defentity address) (defentity user (has-one address)) (select user
(with address) (fields :firstName :lastName :address.state) (where {:email "
[email protected]
"}))
)POFZ42- ‣ Ϛοϓ͔ΒΫΤϦΛ࡞ΔΫΤϦϏϧμʔ ‣ ςʔϒϧఆٛͷखஈ͍࣋ͬͯͳ͍ (-> (select :*) (from :foo)
(where [:= :f.a "baz"])) ;=> {:from [:foo], :where [:= :f.a "baz"], :select (:*)} (-> (select :*) (from :foo) (where [:= :f.a "baz"]) sql/format) ;=> ["SELECT * FROM foo WHERE f.a = ?" "baz"]
:FTRM)VH42- ໊લΛΞϊςʔτ͞Εͨ42-͔ΒؔΛಈతʹੜ͢Δ -- name: users-by-country SELECT * FROM users WHERE
country_code = :country_code (defqueries "users_by_country.sql" {:connection db-spec}) (users-by-country {:country_code "GB"}) users_by_country.sql users_by_country.clj
42-ϑΝʔετΞϓϩʔν ‣ 42-ͦΕ͕ࣗ%4- ‣ %4-ͷ্ʹ%4-Λߏங͢Δͷҙຯ͕͋Δͷ͔ʁ ‣ 42-Λॻ͘͜ͱͰ3%#͝ͱʹదͨ͠ΫΤϦΛ هड़Ͱ͖Δ
ͦͯ͠୭Βͳ͘ͳͬͨ ‣ 42-ϑΝʔετΞϓϩʔνΛͱΔ͜ͱͰɺ$MPKVSF ϨϕϧͰςʔϒϧఆ͚ٛͩͰͳ͘ΫΤϦʹ͍ͭͯ ୭Βͳ͘ͳΔ ‣ 42-ϑΝʔετΞϓϩʔνΛͱΔϥΠϒϥϦ͕͋Δ ͜ͱΛఆ্ͨ͠ͰཧαΠτͷΑ͏ͳػೳΛఏڙ ͢ΔϥΠϒϥϦΛߏஙͰ͖Δͷ͔ʁ
BENJOLJU "ENJOTJUFBTEBUB
BENJOLJU ‣ 3JOHϋϯυϥͱͯ͠࡞ΒΕͨཧαΠτϥΠϒϥϦ ‣ ґଘੑͷٯసʹΑͬͯ%#ʹඇґଘ ‣ $MPKVSFʹΑΔ"1*αʔόͱ$MPKVSF4DSJQUʹΑΔ 41"ͷߏ
ґଘੑٯసͷݪଇ ্ҐϞδϡʔϧԼҐϞδϡʔϧʹґଘ͖͢Ͱͳ͍ɻ ͲͪΒͷϞδϡʔϧநʹґଘ͖͢Ͱ͋Δɻ https://en.wikipedia.org/wiki/Dependency_inversion_principle ΑΓ༁ high level module low level
module high level module abstraction low level module ͷґଘ͕ͳ͘ͳΓ ૄ݁߹ʹͳΔ
ґଘੑͷٯస Ξμϓλʔͱը໘ఆٛ QBHFTQFD ͱ͍͏நΛՃ Admin site ORM RDBMS Admin site
DB wrapper RDBMS adapter/spec యܕతͳཧαΠτͷߏ BENJOLJUͷߏ
ߏཁૉ ‣ Ξμϓλʔ $36%ૢ࡞Λ3%#ϥΠϒϥϦҕৡ͢Δ ‣ ը໘ఆٛ QBHFTQFD
ฤूϑΥʔϜΛϨΠΞτ͠ɺΛͲ͏දࣔ͢Δ͔Λ نఆ͢Δ εΩʔϚఆٛͰͳ͋͘͘·ͰσʔλͷݟͨΛنఆ
Ξμϓλʔ :FTRMΛ͏ྫ -- name: all-products SELECT * FROM products (require
'[admin-kit.adapter :as adapter]) (defqueries "products.sql" {:connection db-spec}) (adapter/make-adapter {:create … :read all-products :update … :delete …}) products.sql products_adapter.clj
ը໘ఆٛ QBHFTQFD (def products-spec {:title "" :fields [{:name :_id :label
"ID" :format #(format "%03d" %) :detail? true} {:name :name :label "໊" :type :text} {:name :furigana :label "ϑϦΨφ" :type :text :sortable? true} … ]}) Ұཡը໘ ฤूը໘
͍ํ ͨͩͷ3JOHϋϯυϥͳͷͰɺ3JOHϛυϧΣΞͱ Έ߹Θͤͯ͏͜ͱ͕Ͱ͖Δ (require '[admin-kit.handler :as handler]) (def site-spec {:products
{:spec products-spec, :adapter products-adapter} …}) (def app (handler/make-admin-site-handler site-spec)) (jetty/run-jetty app {:port 8080})
ར ‣ ଞͷ8FCΞϓϦͷࠐΈͷ༰қ͞ ‣ σʔλιʔεඇґଘ 3%#ʹݶΒͣɺ/P42-ͰϑΝΠϧγεςϜͰΞμ ϓλ͑͞ॻ͚ରԠͰ͖Δ ‣ ΧελϚΠζੑͷߴ͞
ը໘ఆٛΛࣗͰॻͨ͘ΊΧελϚΠζ͕༰қ ϑΥʔϜͷछྨϚϧνϝιουΛॻ͘͜ͱͰ૿ͤΔ
ఆ͞ΕΔ ‣ ΞμϓλΛखͰॻ͘ͷ͕μϧ͍ʜ ϚΫϩΛॻ͜͏ɻϥΠϒϥϦϨϕϧΑΓΞϓϦϨϕ ϧͰͷநԽ͕Γ͍͢߹ଟ͍ɻ ‣ ը໘ఆٛΛखͰॻ͘ͷ͕μϧ͍ʜ ࣮༻తͳΞϓϦͷ߹ɺࣗಈੜ͞Εͨը໘Ͱෆे
ͳ͜ͱଟ͘ͲͷΈͪΧελϚΠζ͕ඞཁʹͳΔ ը໘ఆٛσʔλͳͷͰɺεΩʔϚఆ͔ٛΒࣗಈੜ Λ͢ΔπʔϧΛ࡞Δ͜ͱෆՄೳͰͳ͍
ࠓޙͷ՝ ‣ ଟରଟؔ࿈ϑΟʔϧυରԠ ‣ ϑΟϧλػೳՃ ‣ ϑϩϯτΤϯυଆΛ3FBDUίϯϙʔωϯτʹׂ͠ɺ Ϣʔβ͕ࣗ༝ʹΈ߹ΘͤΒΕΔΑ͏ʹ͢Δ ‣ υΩϡϝϯτඋ
Έ߹ΘͤՄೳͳ ϥΠϒϥϦΛ࡞Δख͕͔Γ ఆ
Έ߹ΘͤՄೳͳ ϥΠϒϥϦΛ࡞Δख͕͔Γ ఆ ‣ ͜Ε·ͰͷBENJOLJUͷ։ൃ͔Βಘͨڭ܇ ‣ ݸʑʹ৽͍͠ͷͳ͍ ػೳΛ๊͑ࠐ·ͳ͍
طଘͷΈ߹ΘͤՄೳͳΈʹ͔ͬΔ ػೳΛϞϊϦγοΫʹ࡞Γࠐ·ͳ͍ நʹґଘ͢Δ
ػೳΛ๊͑ࠐ·ͳ͍ ‣ ػೳΛ࣋ͭͱଞͷϥΠϒϥϦͱڝ߹ͯ͑͠ͳ͍Մ ೳੑ͕ߴ·Δ ‣ ଞͷϥΠϒϥϦʹͤΒΕΔػೳͰ͋Εɺ҆қʹ औΓࠐ·ͳ͍
طଘͷΈ߹ΘͤՄೳͳ Έʹ͔ͬΔ ‣ ଞͷϥΠϒϥϦͱΈ߹ΘͤՄೳʹ͢ΔͯͬͱΓૣ͍ ํ๏طଘͷΈʹ͔ͬΔ͜ͱ ‣ طଘͷΈ߹ΘͤՄೳͳΈͷྫɿ 3JOHͷϋϯυϥ ̋
ɾϛυϧΣΞ ˕ -FJOJOHFOͷλεΫ ˚ ɾߴ֊λεΫ ̋
ػೳΛϞϊϦγοΫʹ࡞Γࠐ·ͳ͍ ‣ Ϣʔβ͕ϥΠϒϥϦͷఏڙ͢ΔػೳΛ෦తʹ͔͠ Θͳ͍ɺ·ͨҰ෦ΛࣗલͰஔ͖͑ͯ͏߹ Λఆ ‣ ػೳ͕ΑΓϓϦϛςΟϒͳ෦ʹׂՄೳͳઃܭʹ ͳ͍ͬͯΕϢʔβ͕༻͢Δ෦ΛબͰ͖Δ
நʹґଘ͢Δ ‣ ଞͷϥΠϒϥϦʹґଘ͢Δ߹Ұ୴நΛڬΜͰ ϥΠϒϥϦͱͷ݁߹Λૄʹอͭ ‣ ந͕ଟա͗Δͱ͍ʹ͘͘ͳΔͷͰɺͲ͜ʹந Λஔ͔͘τϨʔυΦϑΛߟ͑Δඞཁ͕͋Δ
·ͱΊ ‣ ʮϑϨʔϜϫʔΫΑΓϥΠϒϥϦʯΛਪ͠ਐΊΔͱɺΑΓ ্ҐͷػೳΛϥΠϒϥϦͱͯ͠ఏڙ͢Δͷ͕͘͠ͳΔ ‣ BENJOLJUͰཧαΠτػೳΛϥΠϒϥϦͱͯ͠ఏڙ͢Δ ͜ͱΛࡧ ‣ ґଘੑٯసͷݪଇΛ͏·͘͏͜ͱͰଞͷϥΠϒϥϦ ͱΈ߹Θ͕ͤ༰қͳϥΠϒϥϦΛ࡞Δ͜ͱ͕Մೳ
ࢀߟ ‣ 4JNQMJDJUZ.BUUFST<:PV5VCF> ‣ $MPKVSFOFFETBXFCGSBNFXPSLXJUINPSF NPNFOUVN ‣ :FTRM42-JO42-JO$MPKVSF ‣ BENJOLJU<(JU)VC>