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
280
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
970
kitchen-async: a promising (?) Promise library, or a poor man's core.async
athos
3
410
Clojure 1.9 概要紹介
athos
4
1.4k
ここ最近のClojureScript
athos
5
1.7k
(= ? (+ nREPL Docker))
athos
0
490
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
From Translations to Multi Dimension Entities
alexanderschranz
2
130
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
Haze - Real time background blurring
chrisbanes
1
510
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
Exploring: Partial and Independent Composables
blackbracken
0
100
Go の GC の不得意な部分を克服したい
taiyow
3
790
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
testcontainers のススメ
sgash708
1
120
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
Featured
See All Featured
KATA
mclloyd
29
14k
Faster Mobile Websites
deanohume
305
30k
Building an army of robots
kneath
302
44k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Invisible Side of Design
smashingmag
298
50k
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>