node-db
node-db copied to clipboard
Extending Query via JavaScript
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, but the example was not related to SQL generation at all, which is the most practical way to extend Query. 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
Databaseobject within theQueryobject, so I can call things likename,escape, etc.
If I am just completely missing the boat here, please let me know.