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
Go の GC の不得意な部分を克服したい
taiyow
3
800
CSC305 Lecture 26
javiergs
PRO
0
140
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
110
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
790
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
190
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
780
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Spatial Rendering for Apple Vision Pro
warrenm
0
110
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Fireside Chat
paigeccino
34
3.1k
GitHub's CSS Performance
jonrohan
1030
460k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Code Reviewing Like a Champion
maltzj
520
39k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
4 Signs Your Business is Dying
shpigford
181
21k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Designing for Performance
lara
604
68k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Practical Orchestrator
shlominoach
186
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>