Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dev clause for SQL queries automatic reload #145

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

vollcheck
Copy link
Contributor

This MR changes the query-fn component allowing for auto-reload SQL queries if application operates on :dev profile.

@vollcheck vollcheck marked this pull request as draft September 2, 2024 16:42
@vollcheck vollcheck marked this pull request as ready for review September 2, 2024 16:42
@yogthos
Copy link
Collaborator

yogthos commented Sep 2, 2024

Something like the following would be better in my opinion because it avoids a function call and a deref for the prod case. Since SQL queries can be performance sensitive, it's best to add as little overhead as possible by default.

(defn queries-dev [load-queries]
  (fn
    ([query params]
     (conman/query (load-queries) query params))
    ([conn query params & opts]
     (apply conman/query conn (load-queries) query params opts))))

(defn queries-prod [load-queries]
  (let [queries (load-queries)]
    (fn
      ([query params]
       (conman/query queries query params))
      ([conn query params & opts]
       (apply conman/query conn queries query params opts)))))

(defmethod ig/init-key :db.sql/query-fn
  [_ {:keys [conn options filename filenames env]
      :or   {options {}}}]
  (let [filenames (or filenames [filename])
        load-queries #(apply conman/bind-connection-map conn options filenames)]
    (with-meta
      (if (= env :dev)
        (queries-dev load-queries)
        (queries-prod load-queries))
      {:mtimes (mapv ig-utils/last-modified filenames)})))

@vollcheck
Copy link
Contributor Author

Hey @yogthos, I've just fixed component to your liking

@yogthos yogthos merged commit 4c34516 into kit-clj:master Sep 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants