Skip to content

Commit

Permalink
Make db-queries to work if function (#288)
Browse files Browse the repository at this point in the history
This commits make the db-queries at xiana.db to work if it is a
function. Same functionality as query
  • Loading branch information
gmsvalente authored Apr 18, 2024
1 parent ab1bbd9 commit b2ff4ce
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/xiana/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,20 @@
{:select [:*] :from [:users]}."
{:name ::db-access
:leave
(fn [{query-or-fn :query
db-queries :db-queries
:as state}]
(fn [{query-or-fn :query
db-queries-or-fn :db-queries
:as state}]
(let [datasource (get-in state [:deps :db :datasource])
query (cond
(fn? query-or-fn) (query-or-fn state)
:else query-or-fn)
db-data (cond-> []
query (into (execute datasource query))
db-queries (into (multi-execute! datasource db-queries))
:always seq)]
query (cond
(fn? query-or-fn) (query-or-fn state)
:else query-or-fn)
db-queries (cond
(fn? db-queries-or-fn) (db-queries-or-fn state)
:else db-queries-or-fn)
db-data (cond-> []
query (into (execute datasource query))
db-queries (into (multi-execute! datasource db-queries))
:always seq)]
(assoc-in state [:response-data :db-data] db-data)))
:error
(fn [state]
Expand Down

0 comments on commit b2ff4ce

Please sign in to comment.