Reputation:
1) I have a luminus app. I want to execute multiple db requests within a single db connection, meaning, without having to open a connection a second time. Now I have this:
(defn page1 [id]
(layout/render "page1.html"
(my-var1 (db/get-single-article {:id (Integer/parseInt id)}))))
I want to execute something else, say, db/get-something-else, within the same db connection where db/get-single-article is executed. How?
2) In resources/sql/queries.sql I have this:
-- :name get-single-article :? :1
-- :doc retrieve an article given the id.
SELECT * FROM article
WHERE id = :id
How can I add one more query to this so that it'll execute within db/get-single-article call and return a different result set? Like this:
-- :name get-single-article :? :1
-- :doc retrieve an article given the id.
SELECT * FROM article
WHERE id = :id
select * from another_table
where ...
How can I navigate them those when calling db/get-single-article then?
Upvotes: 1
Views: 235
Reputation: 596
Go ahead and define a second query in your SQL file:
-- :name get-something-else :? :*
select * from another_table where ...
Then assign the query results for both queries with something like this:
(defn page1 [id]
(layout/render "page1.html"
{:my-var1 (db/get-single-article {:id (Integer/parseInt id)})
:my-var2 (db/get-something-else)}))
Upvotes: 1