mariano/node-db — Issue #6: Extending Query via JavaScript
Author: dominicbarnes
Created: 2012-01-12 07:01:18+00:00
State: open

I was wanting to extend the `Query` prototype to allow for some custom query chain helpers. I was really hoping to do this via JavaScript, as I'm not a C programmer.

I've got a hold of the `Query` prototype, and I've seen an [example of extending Query](http://nodejsdb.org/2011/05/node-db-0-6-3-released/), but the example was not related to SQL generation at all. I was really hoping to add my own SQL generation functions. I'm working on a more administrative API, so I was wanting to add methods for `USE`, `CREATE`, `SHOW`, etc.

For example: (here is a wrapper for `USE my_database;`)

Query.prototype.use = function (database) {
this.sql("USE " + this.db.name(database));
return this;
};

* I am using `this.sql()` as a setter (this idea is probably not going to work, I'm not really sure how the C code is handling SQL generation, especially if an SQL command requires several commands that could come in any order)
* I would like some reference to the `Database` object within the `Query` object, so I can call things like `name`, `escape`, etc.

If I am just completely missing the boat here, please let me know.