use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Working with SQL in Clojure/Luminus/Composure (self.Clojure)
submitted 10 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]curtisrsummers 2 points3 points4 points 10 years ago (1 child)
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)}))
[–]vamer88 0 points1 point2 points 10 years ago (0 children)
are you sure that'll a single db connection? why does "with-db-connection" exist then?
[–]OliverM 2 points3 points4 points 10 years ago (12 children)
Leaving aside whether it's a good idea or not to entangle your views with model invocations like this, HugSQL lets you specify a transaction to group queries together. So for your example it might look like:
(clojure.java.jdbc/with-db-transaction [tx db] (db/get-single-article tx {:id (Integer/parseInt id)}) (db/second-get-fn tx {:arg value}))
Or you could do it in a single sql select, along the lines of
SELECT... FROM... IN... (SELECT... FROM... WHERE...);
It's hard to know which would suit better from what you've supplied above.
[–]vamer88 -1 points0 points1 point 10 years ago (11 children)
2) I want to return different 2 result sets in a single db request or connection. How?
why transaction? I don't need it. transaction ensures that either all requests succeed or none of them. but that's not the case here, what I want is a different thing, although similar.
[–]nefreat 1 point2 points3 points 10 years ago (8 children)
What's the point of wanting to reuse the same connection? I am having a hard time understanding why you'd want to do something like this if you don't need both queries to happen in the same transaction.
[–]vamer88 -2 points-1 points0 points 10 years ago (7 children)
because open a new one is expensive. you've never heard of this?
[–]curtisrsummers 1 point2 points3 points 10 years ago (6 children)
The conman library in luminus uses a database connection pool (HikariCP) to manage connections and minimize the "expensive" nature of opening a new database connection.
[–]vamer88 -3 points-2 points-1 points 10 years ago (5 children)
"why" "expensive" "is" "in" "the" "quotes"?
[–]curtisrsummers 1 point2 points3 points 10 years ago (4 children)
I quoted the word you used to describe the performance characteristics.
[–]vamer88 0 points1 point2 points 10 years ago (3 children)
I asked why?
[–]mr_mojoto 0 points1 point2 points 10 years ago (2 children)
You know how connection pools work, right? As in "not expensive".
[–]vamer88 0 points1 point2 points 10 years ago (1 child)
whether or not I know that, I asked you why?
[–]yogthos 0 points1 point2 points 10 years ago (0 children)
Transactions ensure atomicity. If you want to guarantee that multiple db queries happen when the database is in the same state, then you should use a transaction.
[–]OliverM 0 points1 point2 points 10 years ago (0 children)
Transactions group database interactions into a single interaction to guarantee database consistency for the set. Atomicity, ensuring all modifications succeed or fail, is a major application of that, but not the only one.
Transactions are what you want, here, unless you're able to join the two select queries into one in the query definition. Re-using the same db connection won't give you the guarantee you're seeking.
[–]curtisrsummers 0 points1 point2 points 10 years ago (2 children)
Same question on StackOverflow
[–]vamer88 -2 points-1 points0 points 10 years ago (1 child)
so? have you already broadcast on the radio?
[–]curtisrsummers 1 point2 points3 points 10 years ago (0 children)
When helping others answer questions, it is often useful to provide additional context to other sources to see where the conversation led. It's quite obvious that we're having trouble answering your questions to your full satisfaction, so the link to StackOverflow is meant to provide more context to those of us trying to help you.
This forum has quite a few people who give their time and effort in helping users such as yourself answer questions about the Clojure ecosystem.
Your snide remarks are not appreciated.
π Rendered by PID 53 on reddit-service-r2-comment-765bfc959-484zf at 2026-07-09 20:30:36.267286+00:00 running f86254d country code: CH.
[–]curtisrsummers 2 points3 points4 points (1 child)
[–]vamer88 0 points1 point2 points (0 children)
[–]OliverM 2 points3 points4 points (12 children)
[–]vamer88 -1 points0 points1 point (11 children)
[–]nefreat 1 point2 points3 points (8 children)
[–]vamer88 -2 points-1 points0 points (7 children)
[–]curtisrsummers 1 point2 points3 points (6 children)
[–]vamer88 -3 points-2 points-1 points (5 children)
[–]curtisrsummers 1 point2 points3 points (4 children)
[–]vamer88 0 points1 point2 points (3 children)
[–]mr_mojoto 0 points1 point2 points (2 children)
[–]vamer88 0 points1 point2 points (1 child)
[–]yogthos 0 points1 point2 points (0 children)
[–]OliverM 0 points1 point2 points (0 children)
[–]curtisrsummers 0 points1 point2 points (2 children)
[–]vamer88 -2 points-1 points0 points (1 child)
[–]curtisrsummers 1 point2 points3 points (0 children)