diff --git a/lib/hana-store.js b/lib/hana-store.js index 616ed5d..7d668d5 100644 --- a/lib/hana-store.js +++ b/lib/hana-store.js @@ -1,8 +1,8 @@ "use strict"; var _ = require('underscore'), - util = require('util'), - uuid = require('node-uuid'), + util = require('util'), + uuid = require('node-uuid'), hana = require('hdb'), relationalstore = require('./relational-util'); @@ -42,8 +42,8 @@ function escapeSQL(input) { var str = input || ''; return str.replace(/[']/g, function (char) { switch (char) { - case "'": - return "''"; + case "'": + return "''"; } }); } else { @@ -69,15 +69,14 @@ function idvalstm(tableName) { function wherestm(entp, q, columns) { var qok = relationalstore.fixquery(entp, q), - wargs = [], - stm = '', - p; + wargs = [], + stm = '', + p; for (p in qok) { - if(_.isString(qok[p]) || _.isNumber(qok[p]) || _.isBoolean(qok[p])) { + if (_.isString(qok[p]) || _.isNumber(qok[p]) || _.isBoolean(qok[p])) { if (qok[p] && columns[p] && columns[p].dataTypeName && relationalstore.isAllowed(columns[p].dataTypeName)) { var val = relationalstore.getMapper(columns[p].dataTypeName).toSQL(qok[p]); -// wargs.push(quoteprop(p) + ' = ' + quoteval(val.value)); wargs.push(util.format('"%s" = \'%s\'', p, val.value)); } } @@ -93,8 +92,8 @@ function wherestm(entp, q, columns) { function metastm(q) { var params = [], - sf, - sd; + sf, + sd; if (q.sort$) { for (sf in q.sort$) break; @@ -123,7 +122,7 @@ function savestm(ent, tblspec) { entp = relationalstore.makeentp(ent, tblspec), fields = _.keys(entp), cols = [], - vals = []; + vals = []; fields.forEach(function (field) { cols.push(quoteprop(field)); @@ -172,13 +171,13 @@ function selectstm(qent, q, tblspec) { module.exports = function (opts) { var name = 'hana-store', - seneca = this, - desc, - minwait, - dbinst = null, - specifications = null, - tablesmap = {}, - schema = opts.schema || ''; + seneca = this, + desc, + minwait, + dbinst = null, + specifications = null, + tablesmap = {}, + schema = opts.schema || ''; opts.minwait = opts.minwait || MIN_WAIT; opts.maxwait = opts.maxwait || MAX_WAIT; @@ -186,12 +185,11 @@ module.exports = function (opts) { function gettable(schema, ent, cb) { var canon = ent.canon$({object: true}), - table = (canon.base ? canon.base + '_' : '') + canon.name; + table = (canon.base ? canon.base + '_' : '') + canon.name; if (!tablesmap[table]) { - var stm = util.format('select * from SYS.TABLE_COLUMNS where SCHEMA_NAME=\'%s\' and TABLE_NAME=\'%s\'', schema, table); + var stm = util.format('SELECT * FROM SYS.TABLE_COLUMNS WHERE SCHEMA_NAME=\'%s\' AND TABLE_NAME=\'%s\'', schema, table); dbinst.exec(stm, function (err, data) { -// dbinst.db.describe({database: schema, schema: schema, table: table}, function (err, data) { if (err) { return cb(err); } @@ -209,29 +207,11 @@ module.exports = function (opts) { function getid(ent, tblspec, cb) { - if (ent.id$) { return cb(null, ent.id$); } -// if (opts.idtype && 'sequence' === opts.idtype) { -// dbinst.query(quoteprop(tblspec.schemaName), idvalstm(tblspec.tableName), function (err, data) { -// if (err) { -// return cb(err); -// } -// var hasData = data && data.rows && data.rows[0]; -// if (hasData) { -// for (var p in data.rows[0]) { -// var id = data.rows[0][p]; -// } -// return cb(null, id); -// } else { -// return cb(null, null); -// } -// }); -// } else { return cb(null, uuid.v4()); -// } } function configure(spec, cb) { @@ -303,7 +283,7 @@ module.exports = function (opts) { save: function (args, cb) { var ent = args.ent, - update = !!ent.id; + update = !!ent.id; gettable(schema, ent, function (err, tblspec) { if (err) { @@ -315,7 +295,7 @@ module.exports = function (opts) { dbinst.exec(stm, function (err, rows) { if (!error(args, err, cb)) { seneca.log(args.tag$, 'update', ent); - ent.load$(ent.data$(),function (err, dbent) { + ent.load$(ent.data$(), function (err, dbent) { if (err) { return cb(err); } @@ -333,7 +313,7 @@ module.exports = function (opts) { dbinst.exec(stm, function (err, rows) { if (!error(args, err, cb)) { seneca.log(args.tag$, 'save/insert', ent); - ent.load$(ent.data$(),function (err, dbent) { + ent.load$(ent.data$(), function (err, dbent) { if (err) { return cb(err); } @@ -350,7 +330,7 @@ module.exports = function (opts) { load: function (args, cb) { var qent = args.qent, - q = args.q; + q = args.q; gettable(schema, qent, function (err, tblspec) { if (err) { @@ -370,8 +350,8 @@ module.exports = function (opts) { list: function (args, cb) { var qent = args.qent, - q = args.q, - list = []; + q = args.q, + list = []; gettable(schema, qent, function (err, tblspec) { if (err) { @@ -395,7 +375,7 @@ module.exports = function (opts) { remove: function (args, cb) { var qent = args.qent, - q = args.q; + q = args.q; gettable(schema, qent, function (err, tblspec) { if (err) { @@ -430,8 +410,7 @@ module.exports = function (opts) { native: function (args, cb) { -// cb(null, dbinst); - cb() + return cb(null, dbinst); } }; diff --git a/package.json b/package.json index 6871f00..f86c4b6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "store", "sap", "hana", - "odbc" + "hdb" ], "scripts": {}, "dependencies": {