얌마들아 아래 질문에도 있다만, 프로그래밍을 컴퓨터 앞에서 오래 앉아서 한다고 실력이 느는게 아녀. 사고를 하고 그걸 프로그램으로 만들 줄 알아야지


생각없이 백날을 컴퓨터 앞에서 키보드 뚜드려 봐라 그게 무슨 노동력 위주의 땔감 코딩이지 제대로 된 프로그램인가.


에를들어 내가 지금 하는 일에서 DB 스키마 추가 혹은 변경 때마다, 또 RESTful 리소스 추가 변경 할때마다 일련의 노가다가 줄줄이 나오고, 실수도 많이하고, 체계적으로 쿼리를 분석할 수도 없고 해서 아예 DB 스키마 원본을 서버에서 보관하고 런타임에 쿼리를 찍어내게 바꿈.


 

이런 DSL 정의를 원본으로 해서 HTTP 요청 URL 맵핑도 하고, DB 쿼리도 만들고, 들어오는 데이터 구조와 타입도 체크하고 그러는 거지.

(def-resource Company

  [{:oid         {:type :bigserial :primary-key true}}

   {:company    {:type :bigint :not-null true :references [Company :oid]}}

   {:worker-oid {:type :bigint :not-null true :references [Worker :oid]}}

   {:worker {:type :join :join-info {:home-key :worker-oid :foreign-key :oid

                                            :join-resource Worker

                                            :foreign-columns [:oid :worker :sys-ctime]

                                            :singular? true}}}

   {:sys-ctime   {:type [:timestamp :without-time-zone] :not-null true :default :clock-timestamp}}]


  :resource-paths #{["company"] ["country" "company"]}

  :row-level-security {:using "valid_company_p(company)"

                       :with-check "valid_company_p(company)"}

  :meta-resource-type :db-resource)


기존에 딴 생키가 해논 코드는 존나 땔감용 노동시간 존나 투입하고 밤늦게 까지 노가다성 코딩해논건데, 걍 아무 생각없이 손으로 죽어라 코딩만 해논거라 보면 됨.



기존껀 URL마다 핸들러를 손수 노가다를 투입해서 수백라인을 짜놓셨는데, 내가 아기자기 하게 함수 두개로 바꿔버림.


(defn handle-web-request [req]

  (if-let [[meta-resource company-oid resource-oid] (req->meta-resource+company+oid req)]

    ;; *rls-company-id* will be used for Postgres Row Level Security

    (binding [*rls-company-id* company-oid]

      (resource-entity (assoc req

                              :meta-resource meta-resource

                              :resource-oid resource-oid

                              :identity (req->identity req)

                              :query-params (-> req :query-params ->clojure-map)

                              :form-params (-> req :form-params ->clojure-map)

                              )))

    (ok (if (re-find oauth-test-uri (:uri req))

          test-html

          "Hello World!"))))


(defn http-request-handler [req]

  (try (with-channel req channel

         (send! channel ((-> handle-web-request

                             wrap-cookies

                             wrap-params

                             (wrap-cors :access-control-allow-origin [#".*"]

                                        :access-control-allow-methods [:get :put :post :delete :patch :options]

                                        :access-control-allow-credentials true

                                        :access-control-allow-headers [

                                                                       "Keep-Alive"

                                                                       "User-Agent"

                                                                       "X-Requested-With"

                                                                       "If-Modified-Since"

                                                                       "Cache-Control"

                                                                       "Content-Type"

                                                                       "X-Auth-Token"

                                                                       "Accept"

                                                                       "Origin"]))

                         req)))

       (catch Exception e

         (error e))))



한줄요약: 니들은 생각이 없다. 왜냐하면 생각이 없기 때문이다.