node-persist
node-persist copied to clipboard
Some issues with Oracle DB
- sqltree.js: To accept CHAR(1) Oracle "boolean" toObject: function (row, result) { ... if (column.modelColumn.type === type.BOOLEAN && (val !== null)) { //val = !!val; val = [true, 1].indexOf(val) != -1 || (val.length > 0 && ['T', 't', 'Y', 'y', '1'].indexOf(val[0]) != -1); (probably, setter requires changes too, Delphi uses 'F' / 'T' in SetAsBoolean()
- driver.js: Oracle does not permit quoted columns in ORDER BY getSqlFromSqlTree: function(sqlTree) { ... //var orderByClause = this.escapeColumnName(orderBy.column.alias) + ' '; var orderByClause = orderBy.column.alias + ' ';
- model.js: to accept one-to-many relationship in both directions: Model.hasMany = function (associatedModel, opts) { ... if (opts.through) { ... } else if (opts.createHasOne) { var associatedOpts = {}; associatedOpts.name = opts.hasOneName; associatedOpts.foreignKey = opts.foreignKey; associatedOpts = this.normalizeHasOneOptions(this, associatedOpts); associatedModel.hasOne(this, associatedOpts); } ... Model.hasOne = function (associatedModel, opts) { ... var foreignKeyPropertyName = inflection.camelize(opts.foreignKey, true); if (!this.columns[foreignKeyPropertyName] || !this.columns[foreignKeyPropertyName].foreignKey) { this.addColumn(foreignKeyPropertyName, { type: "int", foreignKey: true }); }
if (opts.createHasMany) {
var associatedOpts = {};
associatedOpts.name = opts.hasManyName;
associatedOpts.foreignKey = opts.foreignKey;
associatedOpts = this.normalizeHasManyOptions(this, associatedOpts);
associatedModel.hasMany(this, associatedOpts);
}
Good luck!
and I also had to modify executeBaton.cpp in order to accept bool values back to DB: void ExecuteBaton::CopyValuesToBaton(ExecuteBaton* baton, v8::Localv8::Array* values) { ... // boolean else if(val->IsBoolean()) { bool b = val->IsTrue(); value->type = VALUE_TYPE_STRING; value->value = new std::string(b ? "T" : "F"); baton->values.push_back(value); } It may be another way to specify trueValue and falseValue just in the model, but for me it's enough
...and, in order to accept "unassigned": // null if(val->IsNull() || val->IsUndefined()) { ...