UNPKG

alasql

Version:

AlaSQL.js - JavaScript SQL database library for relational and graph data manipulation with support of localStorage, IndexedDB, and Excel

39 lines (34 loc) 1.17 kB
/* // // IF for Alasql.js // Date: 03.11.2014 // (c) 2014, Andrey Gershun // */ yy.If = function (params) { return yy.extend(this, params); } yy.If.prototype.toString = function() { var s = K('IF')+' '; s += this.expression.toString(); s += ' '+this.thenstat.toString(); if(this.elsestat) s += ' '+K('ELSE')+NL()+ID()+this.thenstat.toString(); return s; }; // CREATE TABLE //yy.CreateTable.prototype.compile = returnUndefined; yy.If.prototype.execute = function (databaseid,params,cb){ var res; // console.log(this); // console.log(this.expression.toJavaScript('{}','',null)); // console.log(); var fn = new Function('params,alasql,p','return '+this.expression.toJavaScript('({})','',null)).bind(this); // var fn = new Function('params,alasql,p','console.log(this.thenstat);return '+this.expression.toJavaScript('({})','',null)).bind(this); if(fn(params,alasql)) res = this.thenstat.execute(databaseid,params,cb); else { if(this.elsestat) res = this.elsestat.execute(databaseid,params,cb); else { if(cb) res = cb(res); } } // else res = this.elsestat.execute(databaseid,params,cb,scope); return res; };