Skip to content

Commit

Permalink
Merge branch 'release/0.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
agershun committed May 12, 2015
2 parents 4ea4469 + a2fd78e commit d049a55
Show file tree
Hide file tree
Showing 63 changed files with 27,740 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alasql",
"description":"AlaSQL.js - JavaScript SQL database library for relational and graph data manipulation with support of localStorage, IndexedDB, and Excel",
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",
"keywords": [
"sql",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 0.1.5 "San Marino" (12.05.2015 - 12.05.2015)
* Added Meteor package (agershun:alasql) - still does not work - skeleton
* Northwind test database - test for speed and SQL
* Added w3 database (Northwind analogue)
* Fixed FOREIGN KEY problem

### 0.1.4 "Napoli" (09.05.2015 - 11.05.2015)
* Convert Meteor/Mongo collections on the fly
* Added METEOR() from-function
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# AlaSQL.js - JavaScript SQL database library for relational and graph data manipulation with support of localStorage, IndexedDB, and Excel

Version: 0.1.4 "Napoli" Date: May 11, 2015 [Change log](CHANGELOG.md), [Release plan](RELEASES.md)
Version: 0.1.5 "San Marino" Date: May 12, 2015 [Change log](CHANGELOG.md), [Release plan](RELEASES.md)

AlaSQL - '[à la SQL](http://en.wiktionary.org/wiki/%C3%A0_la)' - is a lightweight JavaScript SQL database designed to work in browser, Node.js, and Apache Cordova. It supports traditional SQL with some NoSQL functionality. Current version of AlaSQL can work in memory and use file, IndexedDB, and localStorage as a persistent storage.

AlaSQL is easy to use! Just add [alasql.min.js](alasql.min.js) file (about 280Kb) to your project and call
AlaSQL is easy to use! Just add [alasql.min.js](alasql.min.js) file to your project and call
```alasql()``` function with SQL statement inside:

```html
Expand Down Expand Up @@ -45,7 +45,7 @@ Check AlaSQL vs other JavaScript SQL databases and data processing libraries:
* [AlaSQL vs. SQL.js](http://jsperf.com/sql-js-vs-alasql-js/4) - in-memory operations* [AlaSQL vs. Linq](http://jsperf.com/alasql-vs-linq-on-groupby) - test on 2^20 records
* AlaSQL vs. CrossFilter - [test 1](http://jsperf.com/alasql-vs-crossfilter), [test 2 on 8000 records](http://jsperf.com/alasql-vs-crossfilter-athletic-data)
* [AlaSQL vs. Lodash](http://jsperf.com/alasql-vs-lodash), [AlaSQL vs. Lodash vs. Underscore](http://jsperf.com/alasql-vs-lodash-sort/3)
* [AlaSQL vs. Human](http://jsperf.com/javascript-array-grouping/7) :) - based on SatckOverflow [question on grouping](http://stackoverflow.com/questions/6781722/fast-grouping-of-a-javascript-array).
* [AlaSQL vs. Human](http://jsperf.com/javascript-array-grouping/10) :) - based on SatckOverflow [question on grouping](http://stackoverflow.com/questions/6781722/fast-grouping-of-a-javascript-array).

## What is new?

Expand Down Expand Up @@ -845,5 +845,5 @@ and other people for useful tools, which make our work much easier.

The MIT license on this repo covers all contents of the repo, but does not supercede the existing licenses for products used for this work, including the Chinook Database (covered by the Microsoft Public License) and other products.

(c) 2014, Andrey Gershun ([email protected]),
(c) 2014-2015, Andrey Gershun ([email protected]),

51 changes: 33 additions & 18 deletions alasql.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// alasql.js
// AlaSQL - JavaScript SQL database
// Date: 11.05.2015
// Version: 0.1.4
// Date: 12.05.2015
// Version: 0.1.5
// (ñ) 2014-2015, Andrey Gershun
//

Expand Down Expand Up @@ -111,7 +111,7 @@ var alasql = function(sql, params, cb, scope) {
};

/** Current version of alasql */
alasql.version = "0.1.4";
alasql.version = "0.1.5";



Expand Down Expand Up @@ -1202,7 +1202,7 @@ case 485: case 486:
this.$ = {foreignkey:{table:$$[$0-1], columnid: $$[$0]}};
break;
case 487:
this.$ = {auto_increment:true};
this.$ = {identity:{value:1,step:1}};
break;
case 488:
this.$ = {identity: {value:$$[$0-3],step:$$[$0-1]}}
Expand Down Expand Up @@ -4016,6 +4016,8 @@ var Database = alasql.Database = function (databaseid) {
} else {
// Create new database (or get alasql?)
self = alasql.databases.alasql;
// For SQL Server examples, USE tempdb
if(alasql.options.tsql) alasql.databases.tempdb = alasql.databases.alasql;
// self = new Database(databaseid); // to call without new
}
}
Expand Down Expand Up @@ -10019,9 +10021,9 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
identity: col.identity
};
if(col.identity) {
table.identities[col.columnid]={value:col.identity.value,step:col.identity.step};
ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
+tableid+'\'].identities[\''+col.columnid+'\'].value)');
table.identities[col.columnid]={value:+col.identity.value,step:+col.identity.step};
// ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
// +tableid+'\'].identities[\''+col.columnid+'\'].value)');
}
if(col.check) {
table.checkfn.push(new Function("r",'return '+col.check.expression.toJavaScript('r','')));
Expand Down Expand Up @@ -10075,7 +10077,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// console.log(r, rr, addr);
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
if(!fktable.uniqs[fktable.pk.hh][addr]) {
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
}
return true;
};
Expand Down Expand Up @@ -10146,7 +10148,8 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// console.log(r, rr, addr);
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
if(!fktable.uniqs[fktable.pk.hh][addr]) {
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
//console.log(228,table,col,fk);
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
}
return true;
};
Expand Down Expand Up @@ -10180,6 +10183,16 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// r[ident.columnid] = ident.value;
// });
// }
//console.log(262,r);
//console.log(263,table.identities)
for(var columnid in table.identities){
var ident = table.identities[columnid];
// console.log(ident);
r[columnid] = ident.value;
// console.log(ident);
};
//console.log(270,r);


if(table.checkfn && table.checkfn.length>0) {
table.checkfn.forEach(function(checkfn){
Expand All @@ -10198,7 +10211,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
var pk = table.pk;
var addr = pk.onrightfn(r);
if(typeof table.uniqs[pk.hh][addr] != 'undefined') {
throw new Error('Cannot insert record, because it already exists in primary key');
throw new Error('Cannot insert record, because it already exists in primary key index');
}
// table.uniqs[pk.hh][addr]=r;
}
Expand All @@ -10214,16 +10227,18 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

// Final change before insert


table.data.push(r);
// Update indices


for(var columnid in table.identities){
var ident = table.identities[columnid];
// console.log(ident);
ident.value += ident.step;
// console.log(ident);
};

table.data.push(r);
// Update indices

if(table.pk) {
var pk = table.pk;
var addr = pk.onrightfn(r);
Expand All @@ -10238,7 +10253,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

};

table.delete = function(i) {
table.delete = function(i,params,alasql) {
var table = this;
var r = this.data[i];
if(this.pk) {
Expand Down Expand Up @@ -11597,7 +11612,7 @@ yy.Insert.prototype.compile = function (databaseid) {
s += 'return '+self.values.length;
}

//console.log(s);
//console.log(186,s3+s);
var insertfn = new Function('db, params, alasql',s3+s);

// INSERT INTO table SELECT
Expand Down Expand Up @@ -11708,7 +11723,7 @@ yy.Delete.prototype.compile = function (databaseid) {
// console.log(this, 22, this.where.toJavaScript('r',''));
// } catch(err){console.log(444,err)};
// var query = {};
wherefn = new Function('r,params','return ('+this.where.toJavaScript('r','')+')');
wherefn = new Function('r,params,alasql','return ('+this.where.toJavaScript('r','')+')');
// console.log(wherefn);
statement = (function (params, cb) {
if(db.engineid && alasql.engines[db.engineid].deleteFromTable) {
Expand All @@ -11725,10 +11740,10 @@ yy.Delete.prototype.compile = function (databaseid) {

var newtable = [];
for(var i=0, ilen=table.data.length;i<ilen;i++) {
if(wherefn(table.data[i],params)) {
if(wherefn(table.data[i],params,alasql)) {
// Check for transaction - if it is not possible then return all back
if(table.delete) {
table.delete(i);
table.delete(i,params,alasql);
} else {
// SImply do not push
}
Expand Down
14 changes: 7 additions & 7 deletions console/alasql.min.js

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions dist/alasql.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// alasql.js
// AlaSQL - JavaScript SQL database
// Date: 11.05.2015
// Version: 0.1.4
// Date: 12.05.2015
// Version: 0.1.5
// (ñ) 2014-2015, Andrey Gershun
//

Expand Down Expand Up @@ -111,7 +111,7 @@ var alasql = function(sql, params, cb, scope) {
};

/** Current version of alasql */
alasql.version = "0.1.4";
alasql.version = "0.1.5";



Expand Down Expand Up @@ -1202,7 +1202,7 @@ case 485: case 486:
this.$ = {foreignkey:{table:$$[$0-1], columnid: $$[$0]}};
break;
case 487:
this.$ = {auto_increment:true};
this.$ = {identity:{value:1,step:1}};
break;
case 488:
this.$ = {identity: {value:$$[$0-3],step:$$[$0-1]}}
Expand Down Expand Up @@ -4016,6 +4016,8 @@ var Database = alasql.Database = function (databaseid) {
} else {
// Create new database (or get alasql?)
self = alasql.databases.alasql;
// For SQL Server examples, USE tempdb
if(alasql.options.tsql) alasql.databases.tempdb = alasql.databases.alasql;
// self = new Database(databaseid); // to call without new
}
}
Expand Down Expand Up @@ -10019,9 +10021,9 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
identity: col.identity
};
if(col.identity) {
table.identities[col.columnid]={value:col.identity.value,step:col.identity.step};
ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
+tableid+'\'].identities[\''+col.columnid+'\'].value)');
table.identities[col.columnid]={value:+col.identity.value,step:+col.identity.step};
// ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
// +tableid+'\'].identities[\''+col.columnid+'\'].value)');
}
if(col.check) {
table.checkfn.push(new Function("r",'return '+col.check.expression.toJavaScript('r','')));
Expand Down Expand Up @@ -10075,7 +10077,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// console.log(r, rr, addr);
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
if(!fktable.uniqs[fktable.pk.hh][addr]) {
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
}
return true;
};
Expand Down Expand Up @@ -10146,7 +10148,8 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// console.log(r, rr, addr);
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
if(!fktable.uniqs[fktable.pk.hh][addr]) {
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
//console.log(228,table,col,fk);
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
}
return true;
};
Expand Down Expand Up @@ -10180,6 +10183,16 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// r[ident.columnid] = ident.value;
// });
// }
//console.log(262,r);
//console.log(263,table.identities)
for(var columnid in table.identities){
var ident = table.identities[columnid];
// console.log(ident);
r[columnid] = ident.value;
// console.log(ident);
};
//console.log(270,r);


if(table.checkfn && table.checkfn.length>0) {
table.checkfn.forEach(function(checkfn){
Expand All @@ -10198,7 +10211,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
var pk = table.pk;
var addr = pk.onrightfn(r);
if(typeof table.uniqs[pk.hh][addr] != 'undefined') {
throw new Error('Cannot insert record, because it already exists in primary key');
throw new Error('Cannot insert record, because it already exists in primary key index');
}
// table.uniqs[pk.hh][addr]=r;
}
Expand All @@ -10214,16 +10227,18 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

// Final change before insert


table.data.push(r);
// Update indices


for(var columnid in table.identities){
var ident = table.identities[columnid];
// console.log(ident);
ident.value += ident.step;
// console.log(ident);
};

table.data.push(r);
// Update indices

if(table.pk) {
var pk = table.pk;
var addr = pk.onrightfn(r);
Expand All @@ -10238,7 +10253,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

};

table.delete = function(i) {
table.delete = function(i,params,alasql) {
var table = this;
var r = this.data[i];
if(this.pk) {
Expand Down Expand Up @@ -11597,7 +11612,7 @@ yy.Insert.prototype.compile = function (databaseid) {
s += 'return '+self.values.length;
}

//console.log(s);
//console.log(186,s3+s);
var insertfn = new Function('db, params, alasql',s3+s);

// INSERT INTO table SELECT
Expand Down Expand Up @@ -11708,7 +11723,7 @@ yy.Delete.prototype.compile = function (databaseid) {
// console.log(this, 22, this.where.toJavaScript('r',''));
// } catch(err){console.log(444,err)};
// var query = {};
wherefn = new Function('r,params','return ('+this.where.toJavaScript('r','')+')');
wherefn = new Function('r,params,alasql','return ('+this.where.toJavaScript('r','')+')');
// console.log(wherefn);
statement = (function (params, cb) {
if(db.engineid && alasql.engines[db.engineid].deleteFromTable) {
Expand All @@ -11725,10 +11740,10 @@ yy.Delete.prototype.compile = function (databaseid) {

var newtable = [];
for(var i=0, ilen=table.data.length;i<ilen;i++) {
if(wherefn(table.data[i],params)) {
if(wherefn(table.data[i],params,alasql)) {
// Check for transaction - if it is not possible then return all back
if(table.delete) {
table.delete(i);
table.delete(i,params,alasql);
} else {
// SImply do not push
}
Expand Down
2 changes: 1 addition & 1 deletion dist/alasql.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/alasql.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit d049a55

Please sign in to comment.