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
Realtime API 入門
riofujimon
0
150
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Quine, Polyglot, 良いコード
qnighy
4
650
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Better Code Design in PHP
afilina
PRO
0
130
CSC509 Lecture 13
javiergs
PRO
0
110
C++でシェーダを書く
fadis
6
4.1k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Ethereum_.pdf
nekomatu
0
470
受け取る人から提供する人になるということ
little_rubyist
0
250
Amazon Qを使ってIaCを触ろう!
maruto
0
410
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
RailsConf 2023
tenderlove
29
900
How STYLIGHT went responsive
nonsquared
95
5.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Fireside Chat
paigeccino
34
3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Unsuck your backbone
ammeep
668
57k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
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>