Comments (7)
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.
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.
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.
- under "with" I meant http://www.postgresql.org/docs/9.3/static/queries-with.html
- 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.
- Ah.. yes. In that sense,
with
is yet to come. - 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.
Ok, thanks then and good luck!
from oj.
Thanks for your interest!
from oj.
Related Issues (14)
- Implement aggregate functions (COUNT, AVERAGE) HOT 8
- Implement Joins
- Implement >= and <= operators in WHERE statements.
- Forcing values in query map for insert/update to be integer or string only prevents lib usage with MySQL boolean columns HOT 2
- Validation fails when creating an update query containing a boolean value HOT 1
- Name the result of aggregate functions in a more friendly way. HOT 4
- Add option to log executed SQL queries to a file instead of just the console.
- Correctly parse Date/Time
- Add a section about aggregate functions to the README
- how to use 'or' in :where HOT 2
- Use parallelism to speed up joins HOT 2
- Use of double quotes as string delimiters in SQL statement causes errors HOT 1
- support for CREATE TABLE? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oj.