Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:31:53+00:00 2026-05-25T15:31:53+00:00

I was reading this site about the clojure web stack: http://brehaut.net/blog/2011/ring_introduction and it has

  • 0

I was reading this site about the clojure web stack:

http://brehaut.net/blog/2011/ring_introduction

and it has this to say about ORM for clojure:

“There are no SQL/Relational DB ORMs for Clojure for obvious reasons.”

The obvious reason I can see is that the mapping to object happens automatically when you do a clojure.contrib.sql or clojureql query. However it seems some extra work is needed to do one-to-many or many-to-many relations (although maybe not too much work).

I found this write up for one-to-many: http://briancarper.net/blog/493/

Which I’m not sure I agree with; it appears to be assuming that both tables are pulled from the database and then the joined table is filtered in memory. In practice I think the sql query would specify the where criteria.

So I’m left wondering, is there some fairly obvious way to automatically do one-to-many relations via clojureql or clojure.contrib.sql? The only thing I can think of is something like this (using the typical blog post/comment example):

(defn post [id] 
    @(-> (table :posts)
        (select (where :id id))))
(defn comments [post_id]
    @(-> (table :comments) 
         (select (where :post_id post_id))))
(defn post-and-comments [id]
    (assoc (post id) :comments (comments id)))

Is there any way to sort of automate this concept or is this as good as it gets?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:31:54+00:00Added an answer on May 25, 2026 at 3:31 pm

    There’s still no high-level library to create complex relational queries that I know of. There’s many ways to tackle this problem (the link you provided is one way) but even if ClojureQL provides a really nice DSL you can build upon, it still miss some important features. Here’s a quick and dirty example of a macro that generate imbricated joins:

    (defn parent-id [parent]
      (let [id (str (apply str (butlast (name parent))) "_id")]
        (keyword (str (name parent) "." id))))
    
    (defn child-id [parent child]
      (let [parent (apply str (butlast (name parent)))]
        (keyword (str (name child) "."  parent "_id"))))
    
    (defn join-on [query parent child]
      `(join ~(or query `(table ~parent)) (table ~child)
             (where
              (~'= ~(parent-id parent)
                   ~(child-id parent child)))))
    
    (defn zip [a b] (map #(vector %1 %2) a b))
    
    (defmacro include [parent & tables]
      (let [pairs (zip (conj tables parent) tables)]
        (reduce (fn [query [parent child]] (join-on query parent child)) nil pairs)))
    

    With this you could do (include :users :posts :comments) and get this SQL out of it:

    SELECT users.*,posts.*,comments.*
      FROM users
      JOIN posts ON (users.user_id = posts.user_id)
      JOIN comments ON (posts.post_id = comments.post_id)
    

    There’s one major issue with this technique though. The main problem is that the returned columns for all tables will be bundled together into the same map. As the column names can’t be qualified automatically, it won’t work if there’s similarly named column in different tables. This also will prevent you from grouping the results without having access to the schema. I don’t think there’s a way around not knowing the database schema for this kind of things so there’s still a lot of work to do. I think ClojureQL will always remain a low-level library, so you’ll need to wait for some other higher-level library to exist or create your own.

    To create such a library, you could always have a look at JDBC’s DatabaseMetaData class to provide information about the database schema. I’m still working on a database analyzer for Lobos that use it (and some custom stuff) but I’m still far from starting to work on SQL queries, which I might add in version 2.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading this link from Steven Sanderson about mobile web development http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
I been reading on asp.net mvc learning site about JavaScript injection and man it
So, in reading this site, it seems that the shop in which I work
I'm a C++ programmer, and I was reading this site when I came across
After reading and commenting on this question PHP Library for Keeping your site index
Reading this post has left me wondering; are nightly builds ever better for a
After reading this discussion and this discussion about using CrashRpt to generate a crash
There are lots of examples on this site about adding to NSMutableArray and I
Yesterday I was reading some articles in this site while I stumbled on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.