orange-orm
Version:
Object Relational Mapper
50 lines (40 loc) • 1.11 kB
JavaScript
var newPara = require('../../query/newParameterized');
var purify = require('./purify');
var getSessionSingleton = require('../../getSessionSingleton');
function _new(column) {
const encode = function(context, candidate) {
var value = purify(candidate);
if (value == null) {
if(column.dbNull === null)
return newPara('null');
return newPara('\'' + column.dbNull + '\'');
}
var encodeCore = getSessionSingleton(context, 'encodeJSON');
if (encodeCore) {
value = encodeCore(value);
}
return newPara('?', [value]);
};
encode.unsafe = function(context, candidate) {
var value = purify(candidate);
if (value == null) {
if(column.dbNull === null)
return 'null';
return '\'' + column.dbNull + '\'';
}
var encodeCore = getSessionSingleton(context, 'encodeJSON');
if (encodeCore) {
value = encodeCore(value);
}
return value;
};
encode.direct = function(context, value) {
var encodeCore = getSessionSingleton(context, 'encodeJSON');
if (encodeCore) {
value = encodeCore(value);
}
return value;
};
return encode;
}
module.exports = _new;