Pro Yearly is on sale from $80 to $50! »

Admin site as data

Admin site as data

Lisp meetup #40の発表資料です。

E170ae2eb0adcf3d136ab0990f0ea671?s=128

OHTA Shogo

May 30, 2016
Tweet

Transcript

  1. "ENJOTJUFBTEBUB Lisp meetup #40 2016/05/30 @athos0220

  2. ؅ཧαΠτͱ͸

  3. ؅ཧαΠτͱ͸ ‣ 8FCΞϓϦͷ؅ཧऀ޲͚ʹ%#΁ͷجຊతͳ$36% ૢ࡞ͷΠϯλʔϑΣʔεΛఏڙ͢Δ ‣ ʮ؅ཧը໘ʯʮ؅ཧϖʔδʯͳͲͱ΋ ‣ %KBOHPͳͲͷ8FCϑϨʔϜϫʔΫ͸Ϟσϧఆ͔ٛ Βࣗಈతʹੜ੒Ͱ͖Δ͜ͱ͕ಛ௃

  4. యܕతͳߏ੒ ‣ %KBOHP΍3BJMT౳ɺଟ͘ͷ؅ཧ αΠτ͸03.ͷଘࡏΛԾఆ ‣ 03.͕3%#΁ͷ$36%ૢ࡞Λ ఏڙ͢Δ ‣ ͞Βʹ03.ͷϞσϧఆ͔ٛΒ ฤूϑΥʔϜΛࣗಈੜ੒͢Δ

    Admin site ORM RDBMS
  5. 5IF$MPKVSF8BZ

  6. γϯϓϧ͞ ‣ $MPKVSFͷجຊతཧ೦ͷͻͱͭ ‣ ΋ͭΕͷͳ͍͜ͱ 㱻DPNQMFDU  ‣ ͭҎ্ͷ΋ͷΛབྷΈ߹ΘͤΔͱෳࡶ ͕͞ੜ͡Δ

    ‣ γϯϓϧ͞͸෭࣍తʹಘΒΕΔ΋ͷ Ͱͳ͘ɺੵۃతʹબͿ΋ͷ
  7. σʔλࢦ޲ ‣ $MPKVSFͰ͸૊ࠐΈσʔλܕΛଟ༻͢Δ ‣ σʔλ͸ੜདྷγϯϓϧͰ͋Γ૊Έ߹ΘͤՄೳ ‣ σʔλʼؔ਺ʼϚΫϩͷॱͰ૊Έ߹ΘͤՄೳੑ͕ߴ·Δ ‣ ҆қʹϚΫϩͰ%4-Λ࡞ΔͷͰ͸ͳ͘ɺσʔλ΍ؔ਺ͱ ͯ͠දݱͰ͖ͳ͍͔Λߟ͑Δ

  8. ϑϨʔϜϫʔΫΑΓϥΠϒϥϦ ‣ ϞϊϦγοΫͳϑϨʔϜϫʔΫ͸ϑϨʔϜϫʔΫࣗମͷݶ քʹୡͨ͠ͱ͖ͷରॲ͕೉͍͠ ‣ ୯ػೳͷϥΠϒϥϦΛ૊Έ߹Θͤͯ࢖͏ํ͕ࣗ༝౓͕ߴ͍ ‣ ͜ͷߟ͔͑Β$MPKVSFʹ͸ϑϨʔϜϫʔΫ ಛʹϑϧελοΫ ͳ8"'

    ͕΄ͱΜͲͳ͍
  9. ʮϑϨʔϜϫʔΫΑΓϥΠϒϥϦʯ ͷ೉͠͞ ‣ ϥΠϒϥϦಉ࢜Λ૊Έ߹ΘͤΔͷ͸Ϣʔβͷ੹೚Ͱɺ ͏·͘ڞଘͤ͞ΒΕͳ͍૊Έ߹Θͤ΋͋Δ  -FJOJOHFOςϯϓϨʔτͰయܕతͳߏ੒Λ࡞ͬͯ͘ΕΔ ΋ͷ΋͋Δ͕ςϯϓϨʔτࣗମͷอक͕೉ ‣ ্ͷϨΠϠʔͷϥΠϒϥϦʹͳΔ΄ͲԼͷϨΠϠʔ

    ʹͲΜͳϥΠϒϥϦ͕དྷΔ͔Λ૝ఆ͖͠Εͳ͍
  10. $MPKVSFʹ͓͚Δ 3%#ϥΠϒϥϦͷมભ

  11. $MPKVSFʹ͓͚Δ 3%#ϥΠϒϥϦͷมભ ‣ 3%#पล͸$MPKVSFϥΠϒϥϦͷதͰ΋৘੎͕มԽ͠ ΍͍͢෼໺ͷͻͱͭ ‣ େ͖ͳྲྀΕͱͯ͠ΑΓγϯϓϧͳํ޲ʹ޲͔͍ͬͯΔ  ,PSNB 

    )POFZ42-  :FTRM)VH42-
  12. ,PSNB ςʔϒϧఆٛɺΫΤϦఆٛ౳ͷ%4-Λ΋ͭ (defentity address) (defentity user (has-one address)) (select user

    (with address) (fields :firstName :lastName :address.state) (where {:email "korma@sqlkorma.com"}))
  13. )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"]
  14. :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
  15. 42-ϑΝʔετΞϓϩʔν ‣ 42-͸ͦΕࣗ਎͕%4- ‣ %4-ͷ্ʹ%4-Λߏங͢Δͷ͸ҙຯ͕͋Δͷ͔ʁ ‣ 42-Λ௚઀ॻ͘͜ͱͰ3%#͝ͱʹదͨ͠ΫΤϦΛ هड़Ͱ͖Δ

  16. ͦͯ͠୭΋஌Βͳ͘ͳͬͨ ‣ 42-ϑΝʔετΞϓϩʔνΛͱΔ͜ͱͰɺ$MPKVSF ϨϕϧͰ͸ςʔϒϧఆ͚ٛͩͰͳ͘ΫΤϦʹ͍ͭͯ ΋୭΋஌Βͳ͘ͳΔ ‣ 42-ϑΝʔετΞϓϩʔνΛͱΔϥΠϒϥϦ͕͋Δ ͜ͱΛ૝ఆ্ͨ͠Ͱ؅ཧαΠτͷΑ͏ͳػೳΛఏڙ ͢ΔϥΠϒϥϦΛߏஙͰ͖Δͷ͔ʁ

  17. BENJOLJU "ENJOTJUFBTEBUB

  18. BENJOLJU ‣ 3JOHϋϯυϥͱͯ͠࡞ΒΕͨ؅ཧαΠτϥΠϒϥϦ ‣ ґଘੑͷٯసʹΑͬͯ%#ʹඇґଘ ‣ $MPKVSFʹΑΔ"1*αʔόͱ$MPKVSF4DSJQUʹΑΔ 41"ͷߏ੒

  19. ґଘੑٯసͷݪଇ ্ҐϞδϡʔϧ͸ԼҐϞδϡʔϧʹґଘ͢΂͖Ͱ͸ͳ͍ɻ ͲͪΒͷϞδϡʔϧ΋ந৅ʹґଘ͢΂͖Ͱ͋Δɻ https://en.wikipedia.org/wiki/Dependency_inversion_principle ΑΓ຋༁ high level module low level

    module high level module abstraction low level module ௚઀ͷґଘ͕ͳ͘ͳΓ ૄ݁߹ʹͳΔ
  20. ґଘੑͷٯస Ξμϓλʔͱը໘ఆٛ QBHFTQFD ͱ͍͏ந৅Λ௥Ճ Admin site ORM RDBMS Admin site

    DB wrapper RDBMS adapter/spec యܕతͳ؅ཧαΠτͷߏ੒ BENJOLJUͷߏ੒
  21. ߏ੒ཁૉ ‣ Ξμϓλʔ  $36%ૢ࡞Λ3%#ϥΠϒϥϦ΁ҕৡ͢Δ ‣ ը໘ఆٛ QBHFTQFD  

    ฤूϑΥʔϜΛϨΠΞ΢τ͠ɺ஋ΛͲ͏දࣔ͢Δ͔Λ نఆ͢Δ  εΩʔϚఆٛͰ͸ͳ͋͘͘·Ͱσʔλͷݟͨ໨Λنఆ
  22. Ξμϓλʔ :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
  23. ը໘ఆٛ 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} … ]}) Ұཡը໘ ฤूը໘
  24. ࢖͍ํ ͨͩͷ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})
  25. ར఺ ‣ ଞͷ8FCΞϓϦ΁ͷ૊ࠐΈͷ༰қ͞ ‣ σʔλιʔεඇґଘ  3%#ʹݶΒͣɺ/P42-Ͱ΋ϑΝΠϧγεςϜͰ΋Ξμ ϓλ͑͞ॻ͚͹ରԠͰ͖Δ ‣ ΧελϚΠζੑͷߴ͞

     ը໘ఆٛΛࣗ෼Ͱॻͨ͘ΊΧελϚΠζ͕༰қ  ϑΥʔϜͷछྨ΋ϚϧνϝιουΛॻ͘͜ͱͰ૿΍ͤΔ
  26. ૝ఆ͞ΕΔ໰୊఺ ‣ ΞμϓλΛखͰॻ͘ͷ͕μϧ͍ʜ  ϚΫϩΛॻ͜͏ɻϥΠϒϥϦϨϕϧΑΓ΋ΞϓϦϨϕ ϧͰͷந৅Խ͕΍Γ΍͍͢৔߹͸ଟ͍ɻ ‣ ը໘ఆٛΛखͰॻ͘ͷ͕μϧ͍ʜ  ࣮༻తͳΞϓϦͷ৔߹ɺࣗಈੜ੒͞Εͨը໘Ͱ͸ෆे

    ෼ͳ͜ͱ͸ଟ͘ͲͷΈͪΧελϚΠζ͕ඞཁʹͳΔ  ը໘ఆٛ͸σʔλͳͷͰɺεΩʔϚఆ͔ٛΒࣗಈੜ੒ Λ͢ΔπʔϧΛ࡞Δ͜ͱ΋ෆՄೳͰ͸ͳ͍
  27. ࠓޙͷ՝୊ ‣ ଟରଟؔ࿈ϑΟʔϧυରԠ ‣ ϑΟϧλػೳ௥Ճ ‣ ϑϩϯτΤϯυଆΛ3FBDUίϯϙʔωϯτʹ෼ׂ͠ɺ Ϣʔβ͕ࣗ༝ʹ૊Έ߹ΘͤΒΕΔΑ͏ʹ͢Δ ‣ υΩϡϝϯτ੔උ

  28. ૊Έ߹ΘͤՄೳͳ ϥΠϒϥϦΛ࡞Δख͕͔Γ ࢑ఆ

  29. ૊Έ߹ΘͤՄೳͳ ϥΠϒϥϦΛ࡞Δख͕͔Γ ࢑ఆ ‣ ͜Ε·ͰͷBENJOLJUͷ։ൃ͔Βಘͨڭ܇ ‣ ݸʑʹ͸໨৽͍͠΋ͷ͸ͳ͍  ػೳΛ๊͑ࠐ·ͳ͍ 

    طଘͷ૊Έ߹ΘͤՄೳͳ࢓૊Έʹ৐͔ͬΔ  ػೳΛϞϊϦγοΫʹ࡞Γࠐ·ͳ͍  ந৅ʹґଘ͢Δ
  30. ػೳΛ๊͑ࠐ·ͳ͍ ‣ ػೳΛ࣋ͭͱଞͷϥΠϒϥϦͱڝ߹ͯ͠࢖͑ͳ͍Մ ೳੑ͕ߴ·Δ ‣ ଞͷϥΠϒϥϦʹ೚ͤΒΕΔػೳͰ͋Ε͹ɺ҆қʹ औΓࠐ·ͳ͍

  31. طଘͷ૊Έ߹ΘͤՄೳͳ ࢓૊Έʹ৐͔ͬΔ ‣ ଞͷϥΠϒϥϦͱ૊Έ߹ΘͤՄೳʹ͢ΔͯͬͱΓૣ͍ ํ๏͸طଘͷ࢓૊Έʹ৐͔ͬΔ͜ͱ ‣ طଘͷ૊Έ߹ΘͤՄೳͳ࢓૊Έͷྫɿ  3JOHͷϋϯυϥ ̋

    ɾϛυϧ΢ΣΞ ˕   -FJOJOHFOͷλεΫ ˚ ɾߴ֊λεΫ ̋
  32. ػೳΛϞϊϦγοΫʹ࡞Γࠐ·ͳ͍ ‣ Ϣʔβ͕ϥΠϒϥϦͷఏڙ͢ΔػೳΛ෦෼తʹ͔͠ ࢖Θͳ͍ɺ·ͨ͸Ұ෦ΛࣗલͰஔ͖׵͑ͯ࢖͏৔߹ Λ૝ఆ ‣ ػೳ͕ΑΓϓϦϛςΟϒͳ෦෼ʹ෼ׂՄೳͳઃܭʹ ͳ͍ͬͯΕ͹Ϣʔβ͕࢖༻͢Δ෦෼Λબ୒Ͱ͖Δ

  33. ந৅ʹґଘ͢Δ ‣ ଞͷϥΠϒϥϦʹґଘ͢Δ৔߹͸Ұ୴ந৅ΛڬΜͰ ϥΠϒϥϦͱͷ݁߹Λૄʹอͭ ‣ ந৅͕ଟա͗Δͱ࢖͍ʹ͘͘ͳΔͷͰɺͲ͜ʹந৅ Λஔ͔͘͸τϨʔυΦϑΛߟ͑Δඞཁ͕͋Δ

  34. ·ͱΊ ‣ ʮϑϨʔϜϫʔΫΑΓϥΠϒϥϦʯΛਪ͠ਐΊΔͱɺΑΓ ্ҐͷػೳΛϥΠϒϥϦͱͯ͠ఏڙ͢Δͷ͕೉͘͠ͳΔ ‣ BENJOLJUͰ؅ཧαΠτػೳΛϥΠϒϥϦͱͯ͠ఏڙ͢Δ ͜ͱΛ໛ࡧ ‣ ґଘੑٯసͷݪଇ౳Λ͏·͘࢖͏͜ͱͰଞͷϥΠϒϥϦ ͱ૊Έ߹Θ͕ͤ༰қͳϥΠϒϥϦΛ࡞Δ͜ͱ͕Մೳ

  35. ࢀߟ ‣ 4JNQMJDJUZ.BUUFST<:PV5VCF> ‣ $MPKVSFOFFETBXFCGSBNFXPSLXJUINPSF NPNFOUVN ‣ :FTRM42-JO42-JO$MPKVSF ‣ BENJOLJU<(JU)VC>