Coder Social home page Coder Social logo

Comments (7)

taylorlapeyre avatar taylorlapeyre commented on September 28, 2024

In korma, SQL queries are compiled by calling functions. In OJ, everything is just data. Queries are represented as a Clojure (query) map that can be manipulated however you wish.

In korma,

(select user
  (fields :firstName :lastName)
  (where {:email "[email protected]"}))

In OJ:

{:table :users
 :select [:firstName :lastName]
 :where {:email "[email protected]"}}

OJ encourages the use of "modifier functions," which take a query map, change it, and return a new one.

(-> (query :users)
    (select  [:firstName :lastName])
    (where {:email "[email protected]"})
    (oj/exec database))

This gives the appearance of a higher level library abstraction, without losing the "everything is just data" mentality.

from oj.

razum2um avatar razum2um commented on September 28, 2024

korma also allows you to do (def scope (-> (select* table) (where {:col true}))

it's a clojure map too, and you can modify it as you wish, but there are quite good functions already some like limit, order and so on ending up in sqlfn and raw as well.
(-> scope (limit 1)) returns scope-map again until calling (-> scope (select))

one known to me korma's limitation is unability to write CTE and with queries for postgres for example.
do you solve this one?

from oj.

taylorlapeyre avatar taylorlapeyre commented on September 28, 2024

The "with" problem is one that I struggled to solve in a way that was acceptable to me. In the end, I went with the concept of a join, which you can find documentation for here.

The default modifier function join tries to be as helpful as possible. If your tables are named in a rails convention, joining another table is as simple as:

(-> (query :users)
    (join :items))
; => SELECT * FROM users
; => SELECT * FROM items WHERE items.user_id = 1
; => SELECT * FROM items WHERE items.user_id = 2
; ... and so on for each user

If not, you can specify the foreign keys:

(-> (query :users)
    (join :items {:user_id :id})

The returned result would look like this:

({:username "blah" :items ({:id 1 :name "Thing"})} ...

I plan on parallelising these subqueries.

from oj.

razum2um avatar razum2um commented on September 28, 2024
  1. under "with" I meant http://www.postgresql.org/docs/9.3/static/queries-with.html
  2. such relying on conventions does appeal to me and i like rails way as well, but would you like to turn it to includes-like?

Anyway, still don't get you why not to join forces and fork korma to push mainstream further?
As I said, it modifies similar map under the hood, but nothing prevents you to modify it by yourself

from oj.

taylorlapeyre avatar taylorlapeyre commented on September 28, 2024
  1. Ah.. yes. In that sense, with is yet to come.
  2. Maybe.

Korma is a great project! I just feel like there can be a simpler, easier to understand, and more elegant solution to interfacing with a database. Forking Korma would mean changing a lot of their API, which means that it would basically be a new project anyway. OJ is my personal solution.

from oj.

razum2um avatar razum2um commented on September 28, 2024

Ok, thanks then and good luck!

from oj.

taylorlapeyre avatar taylorlapeyre commented on September 28, 2024

Thanks for your interest!

from oj.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.