sqlingvo
sqlingvo copied to clipboard
Why pass db into select, insert, create-table, etc when it's actually needed only in sql fn?
Hi Roman.
After reading sqlingvo source I'm confused with db
argument of functions such as select
, insert
and others. db
contains information about how to escape various SQL literals, so it's needed only when generating string representation of SQL AST - in sqlingvo.core.sql
function.
It'll be much more convenient to completely separate AST construction and generation of SQL strings:
(let [select-stmt (select [:*]
(from :foo)
(where '(= :bar 42)))]
(println "PostgreSQL variant:" (sql postgres-db select-stmt))
(println "SQLite variant:" (sql sqlite-db select-stmt))
(println "MySQL variant:" (sql mysql-db select-stmt)))
Or I'm missing something? I can make a pull request if this change makes sense.
Hey mlapshin,
the reason I pass the db to those fns is because in some future I want to be able to do something like the following example:
@(select db [1 2 3])
;=> ({:?column?-3 3, :?column?-2 2, :?column? 1})
I have an other project that builds on top of sqlingvo over here that has some examples in the readme.
https://github.com/r0man/datumbazo
That repo is highly experimental, so I would not recommend building on top of that. :)