Skip to content

Commit

Permalink
Removed unused code (See #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianr committed Jan 19, 2014
1 parent 4ddcb48 commit eeaa11e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 50 deletions.
77 changes: 28 additions & 49 deletions lib/hana-store.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -42,8 +42,8 @@ function escapeSQL(input) {
var str = input || '';
return str.replace(/[']/g, function (char) {
switch (char) {
case "'":
return "''";
case "'":
return "''";
}
});
} else {
Expand All @@ -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));
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -172,26 +171,25 @@ 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;


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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -430,8 +410,7 @@ module.exports = function (opts) {


native: function (args, cb) {
// cb(null, dbinst);
cb()
return cb(null, dbinst);
}

};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"store",
"sap",
"hana",
"odbc"
"hdb"
],
"scripts": {},
"dependencies": {
Expand Down

0 comments on commit eeaa11e

Please sign in to comment.