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
260
軽量デバッグツールPostmortemの紹介.pdf
athos
1
180
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
950
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.6k
(= ? (+ nREPL Docker))
athos
0
480
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
970
Macとオーディオ再生 2024/11/02
yusukeito
0
140
Golang と Erlang
taiyow
8
1.9k
Mastering Dependencies in Kotlin Multiplatform
tomifabian
0
110
qmuntal/stateless のススメ
sgash708
0
120
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
310
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
7
430
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
110
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Fireside Chat
paigeccino
32
3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Automating Front-end Workflow
addyosmani
1365
200k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Practical Orchestrator
shlominoach
186
10k
Adopting Sorbet at Scale
ufuk
73
9k
Happy Clients
brianwarren
97
6.7k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
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>