Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Admin site as data

Admin site as data

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

OHTA Shogo

May 30, 2016
Tweet

More Decks by OHTA Shogo

Other Decks in Programming

Transcript

  1. )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"]
  2. :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
  3. ґଘੑͷٯస Ξμϓλʔͱը໘ఆٛ QBHFTQFD ͱ͍͏ந৅Λ௥Ճ Admin site ORM RDBMS Admin site

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

    ฤूϑΥʔϜΛϨΠΞ΢τ͠ɺ஋ΛͲ͏දࣔ͢Δ͔Λ نఆ͢Δ  εΩʔϚఆٛͰ͸ͳ͋͘͘·Ͱσʔλͷݟͨ໨Λنఆ
  5. Ξμϓλʔ :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
  6. ը໘ఆٛ 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} … ]}) Ұཡը໘ ฤूը໘
  7. ࢖͍ํ ͨͩͷ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})
  8. ૊Έ߹ΘͤՄೳͳ ϥΠϒϥϦΛ࡞Δख͕͔Γ ࢑ఆ ‣ ͜Ε·ͰͷBENJOLJUͷ։ൃ͔Βಘͨڭ܇ ‣ ݸʑʹ͸໨৽͍͠΋ͷ͸ͳ͍  ػೳΛ๊͑ࠐ·ͳ͍ 

    طଘͷ૊Έ߹ΘͤՄೳͳ࢓૊Έʹ৐͔ͬΔ  ػೳΛϞϊϦγοΫʹ࡞Γࠐ·ͳ͍  ந৅ʹґଘ͢Δ