brianc/node-sql

Reduce typing

Opened this issue · 2 comments

Hello -

When I was at nodeconf I was talking to a few people who have used this library in the past and found a weak point. The weak point they usually mentioned was because node-sql relies so heavily on the schema it's impossible to do really complicated query things or extremely dynamic query generation. I was thinking maybe after 1.0 we could brainstorm a bit about how to add ways to insert raw SQL more easily. Of course there will be a trade off for the user because they don't get the verification their query is as correct, but I think having both options available would provide a lot of value. Here's an example of the beginning of an API I was thinking about below....

var user = sql.define({
  name: 'user',
  columns: ['id', 'email']
});

var q = user.select('anything').select('anything else').from('whatever').where('custom where clause');
console.log(q.toQuery().text);
/*
select anything, anything else from whatever where custom where clause;
*/

Having the ability to append arbitrary text nodes anywhere would allow for a lot more extensibility in user-land code without having to hack on node-sql directly. There are a lot more things to explore here but I thought we could open it up for some discussion on ideas.

Just to continue the discussion: the best sql mapping API I've seen is korma from the Clojure ecosystem.

It might be helpful to create some super-complex end result raw SQL queries, and then work backward from there to sketch out some ideal pseudo-APIs.

FWIW, I went ahead & did this (wrote a schema-less sql-generation library) 4 months ago. We've been using it on a couple projects in our company & enjoying it: https://github.com/CSNW/sql-bricks