Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
added asRaw()
Browse files Browse the repository at this point in the history
to get the unprocessed output of your sql backend
  • Loading branch information
Philipp Waldmann committed Jul 7, 2014
1 parent 72d7dd0 commit 6cb6b7c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
39 changes: 32 additions & 7 deletions lib/stores/sql/exec.js
Expand Up @@ -22,6 +22,7 @@ exports.model = {
var query = self.query;

return self.promise(function(resolve, reject){
var as_raw = self.getInternal('as_raw');

self.callInterceptors('beforeFind', self, [query], function(okay){
if(okay){
Expand All @@ -41,13 +42,18 @@ exports.model = {
//console.log(query.toString());
//console.log(query.toString(), resp);

self.callInterceptors('afterFind', self, [data], function(okay){
if(okay){
resolve(data.result);
}else{
resolve(null);
}
}, reject);
if(as_raw){
resolve(data.result);
}else{
self.callInterceptors('afterFind', self, [data], function(okay){
if(okay){
resolve(data.result);
}else{
resolve(null);
}
}, reject);
}

});

}else{
Expand All @@ -69,6 +75,25 @@ exports.model = {
});

return sql.replace(/`/g, '\"');
},


/**
* `exec()` will return the raw store output
* Be aware, that no `afterFind` hook will be fired if you use `asRaw()`.
*
* @class Model
* @method asRaw
*
* @return {Model}
* @see Model.exec()
*/
asRaw: function(){
var self = this.chain();

self.setInternal('as_raw', true);

return self;
}

};
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openrecord",
"version": "1.0.1",
"version": "1.1.0",
"description": "Active record like ORM for nodejs",
"keywords": ["orm", "record", "sql", "sqlite3", "postgres", "pg", "mysql", "database", "activerecord", "promise", "rest", "restify", "nested set"],
"author": "Philipp Waldmann <philipp.waldmann@s-team.at>",
Expand Down

0 comments on commit 6cb6b7c

Please sign in to comment.