We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I can't get this running in window any ideas const _ = require('underscore'); const async = require('async'); const prototype = require('prototype');
//To get include deleted data, add the option {deleted: true} //Other options, you can use from streamsql
var DEFAULT_CONDITION = { deleted: null }
var removeCustomOptions = function (object) { delete object.deleted; }
var Base = Class.create();
Base.prototype = { initialize: function (modelObject) { this.modelObject = modelObject; }, put: function(object, callback) { this.modelObject.put(object, function (err, result) { if (err) { return callback(err); };
var returnObject = {}; returnObject.id = result.insertId; _.extend(returnObject, result.row); return callback(err, returnObject); }); }, get: function(conditions, options, callback){ if (typeof options == 'function') { callback = options; options = {}; }; //if options.deleted != true, meaning want to get not deleted objects if (!options.deleted) { conditions = _.extend(conditions, DEFAULT_CONDITION); }; // options.deleted is a custom options, so we need to remove it before use. removeCustomOptions(options); this.modelObject.get(conditions, options, function (err, results) { if (results.length == 0) { return callback(err, null); } else { return callback(err, results); } }); }, getOne: function(conditions, options, callback) { if (typeof options == 'function') { callback = options; options = {}; }; if (!options.deleted) { conditions = _.extend(conditions, DEFAULT_CONDITION); }; removeCustomOptions(options); this.modelObject.getOne(conditions, options, function (err, result) { return callback(err, result); }); }, getById: function(id, options, callback) { if (typeof options == 'function') { callback = options; options = {}; }; this.getOne({id: id}, options, function (err, result) { return callback(err, result); }) }, getMany: function(options, callback) { this.get({}, options, function (err, results) { return callback(err, results); }) }, update: function(updateObject, callback) { this.put(updateObject, function (err, result) { return callback(err, result); }) }, create: function(object, callback) { this.put(object, function (err, result) { return callback(err, result); }) }, remove: function(id, callback) { var base = this; async.waterfall([ function (innerCallback) { base.getOne({id: id}, function (err, result) { if (err) { return callback(err); }; result.deleted = new Date(); innerCallback(err, result); }) }, function (deletedObject, innerCallback) { base.put(deletedObject, function (err, result) { innerCallback(err, result); }) } ], function (err, result) { callback(err, result); }); }, restore: function(id, callback) { var base = this; async.waterfall([ function (innerCallback) { var options = {deleted: true}; base.getOne({id: id}, options, function (err, result) { if (err) { return callback(err); }; result.deleted = null; innerCallback(err, result); }) }, function (restoredObject, innerCallback) { base.put(restoredObject, function (err, result) { innerCallback(err, result); }) } ], function (err, result) { callback(err, result); }); }, permanentDelete: function(id, callback) { this.modelObject.del({id: id}, function (err) { return callback(err); }); }
} exports = module.exports = Base;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I can't get this running in window any ideas
const _ = require('underscore');
const async = require('async');
const prototype = require('prototype');
//To get include deleted data, add the option {deleted: true}
//Other options, you can use from streamsql
var DEFAULT_CONDITION = {
deleted: null
}
var removeCustomOptions = function (object) {
delete object.deleted;
}
var Base = Class.create();
Base.prototype = {
initialize: function (modelObject) {
this.modelObject = modelObject;
},
put: function(object, callback) {
this.modelObject.put(object, function (err, result) {
if (err) {
return callback(err);
};
}
exports = module.exports = Base;
The text was updated successfully, but these errors were encountered: