Skip to content

Commit d049a55

Browse files
committed
Merge branch 'release/0.1.5'
2 parents 4ea4469 + a2fd78e commit d049a55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+27740
-121
lines changed

.bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "alasql",
33
"description":"AlaSQL.js - JavaScript SQL database library for relational and graph data manipulation with support of localStorage, IndexedDB, and Excel",
4-
"version": "0.1.4",
4+
"version": "0.1.5",
55
"license": "MIT",
66
"keywords": [
77
"sql",

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
### 0.1.5 "San Marino" (12.05.2015 - 12.05.2015)
4+
* Added Meteor package (agershun:alasql) - still does not work - skeleton
5+
* Northwind test database - test for speed and SQL
6+
* Added w3 database (Northwind analogue)
7+
* Fixed FOREIGN KEY problem
8+
39
### 0.1.4 "Napoli" (09.05.2015 - 11.05.2015)
410
* Convert Meteor/Mongo collections on the fly
511
* Added METEOR() from-function

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# AlaSQL.js - JavaScript SQL database library for relational and graph data manipulation with support of localStorage, IndexedDB, and Excel
22

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

55
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.
66

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

1010
```html
@@ -45,7 +45,7 @@ Check AlaSQL vs other JavaScript SQL databases and data processing libraries:
4545
* [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
4646
* AlaSQL vs. CrossFilter - [test 1](http://jsperf.com/alasql-vs-crossfilter), [test 2 on 8000 records](http://jsperf.com/alasql-vs-crossfilter-athletic-data)
4747
* [AlaSQL vs. Lodash](http://jsperf.com/alasql-vs-lodash), [AlaSQL vs. Lodash vs. Underscore](http://jsperf.com/alasql-vs-lodash-sort/3)
48-
* [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).
48+
* [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).
4949

5050
## What is new?
5151

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

846846
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.
847847

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

alasql.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
22
// alasql.js
33
// AlaSQL - JavaScript SQL database
4-
// Date: 11.05.2015
5-
// Version: 0.1.4
4+
// Date: 12.05.2015
5+
// Version: 0.1.5
66
// (ñ) 2014-2015, Andrey Gershun
77
//
88

@@ -111,7 +111,7 @@ var alasql = function(sql, params, cb, scope) {
111111
};
112112

113113
/** Current version of alasql */
114-
alasql.version = "0.1.4";
114+
alasql.version = "0.1.5";
115115

116116

117117

@@ -1202,7 +1202,7 @@ case 485: case 486:
12021202
this.$ = {foreignkey:{table:$$[$0-1], columnid: $$[$0]}};
12031203
break;
12041204
case 487:
1205-
this.$ = {auto_increment:true};
1205+
this.$ = {identity:{value:1,step:1}};
12061206
break;
12071207
case 488:
12081208
this.$ = {identity: {value:$$[$0-3],step:$$[$0-1]}}
@@ -4016,6 +4016,8 @@ var Database = alasql.Database = function (databaseid) {
40164016
} else {
40174017
// Create new database (or get alasql?)
40184018
self = alasql.databases.alasql;
4019+
// For SQL Server examples, USE tempdb
4020+
if(alasql.options.tsql) alasql.databases.tempdb = alasql.databases.alasql;
40194021
// self = new Database(databaseid); // to call without new
40204022
}
40214023
}
@@ -10019,9 +10021,9 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1001910021
identity: col.identity
1002010022
};
1002110023
if(col.identity) {
10022-
table.identities[col.columnid]={value:col.identity.value,step:col.identity.step};
10023-
ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
10024-
+tableid+'\'].identities[\''+col.columnid+'\'].value)');
10024+
table.identities[col.columnid]={value:+col.identity.value,step:+col.identity.step};
10025+
// ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
10026+
// +tableid+'\'].identities[\''+col.columnid+'\'].value)');
1002510027
}
1002610028
if(col.check) {
1002710029
table.checkfn.push(new Function("r",'return '+col.check.expression.toJavaScript('r','')));
@@ -10075,7 +10077,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1007510077
// console.log(r, rr, addr);
1007610078
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
1007710079
if(!fktable.uniqs[fktable.pk.hh][addr]) {
10078-
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
10080+
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
1007910081
}
1008010082
return true;
1008110083
};
@@ -10146,7 +10148,8 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1014610148
// console.log(r, rr, addr);
1014710149
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
1014810150
if(!fktable.uniqs[fktable.pk.hh][addr]) {
10149-
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
10151+
//console.log(228,table,col,fk);
10152+
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
1015010153
}
1015110154
return true;
1015210155
};
@@ -10180,6 +10183,16 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1018010183
// r[ident.columnid] = ident.value;
1018110184
// });
1018210185
// }
10186+
//console.log(262,r);
10187+
//console.log(263,table.identities)
10188+
for(var columnid in table.identities){
10189+
var ident = table.identities[columnid];
10190+
// console.log(ident);
10191+
r[columnid] = ident.value;
10192+
// console.log(ident);
10193+
};
10194+
//console.log(270,r);
10195+
1018310196

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

1021510228
// Final change before insert
1021610229

10230+
10231+
table.data.push(r);
10232+
// Update indices
10233+
10234+
1021710235
for(var columnid in table.identities){
1021810236
var ident = table.identities[columnid];
1021910237
// console.log(ident);
1022010238
ident.value += ident.step;
1022110239
// console.log(ident);
1022210240
};
1022310241

10224-
table.data.push(r);
10225-
// Update indices
10226-
1022710242
if(table.pk) {
1022810243
var pk = table.pk;
1022910244
var addr = pk.onrightfn(r);
@@ -10238,7 +10253,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1023810253

1023910254
};
1024010255

10241-
table.delete = function(i) {
10256+
table.delete = function(i,params,alasql) {
1024210257
var table = this;
1024310258
var r = this.data[i];
1024410259
if(this.pk) {
@@ -11597,7 +11612,7 @@ yy.Insert.prototype.compile = function (databaseid) {
1159711612
s += 'return '+self.values.length;
1159811613
}
1159911614

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

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

1172611741
var newtable = [];
1172711742
for(var i=0, ilen=table.data.length;i<ilen;i++) {
11728-
if(wherefn(table.data[i],params)) {
11743+
if(wherefn(table.data[i],params,alasql)) {
1172911744
// Check for transaction - if it is not possible then return all back
1173011745
if(table.delete) {
11731-
table.delete(i);
11746+
table.delete(i,params,alasql);
1173211747
} else {
1173311748
// SImply do not push
1173411749
}

console/alasql.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/alasql.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
22
// alasql.js
33
// AlaSQL - JavaScript SQL database
4-
// Date: 11.05.2015
5-
// Version: 0.1.4
4+
// Date: 12.05.2015
5+
// Version: 0.1.5
66
// (ñ) 2014-2015, Andrey Gershun
77
//
88

@@ -111,7 +111,7 @@ var alasql = function(sql, params, cb, scope) {
111111
};
112112

113113
/** Current version of alasql */
114-
alasql.version = "0.1.4";
114+
alasql.version = "0.1.5";
115115

116116

117117

@@ -1202,7 +1202,7 @@ case 485: case 486:
12021202
this.$ = {foreignkey:{table:$$[$0-1], columnid: $$[$0]}};
12031203
break;
12041204
case 487:
1205-
this.$ = {auto_increment:true};
1205+
this.$ = {identity:{value:1,step:1}};
12061206
break;
12071207
case 488:
12081208
this.$ = {identity: {value:$$[$0-3],step:$$[$0-1]}}
@@ -4016,6 +4016,8 @@ var Database = alasql.Database = function (databaseid) {
40164016
} else {
40174017
// Create new database (or get alasql?)
40184018
self = alasql.databases.alasql;
4019+
// For SQL Server examples, USE tempdb
4020+
if(alasql.options.tsql) alasql.databases.tempdb = alasql.databases.alasql;
40194021
// self = new Database(databaseid); // to call without new
40204022
}
40214023
}
@@ -10019,9 +10021,9 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1001910021
identity: col.identity
1002010022
};
1002110023
if(col.identity) {
10022-
table.identities[col.columnid]={value:col.identity.value,step:col.identity.step};
10023-
ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
10024-
+tableid+'\'].identities[\''+col.columnid+'\'].value)');
10024+
table.identities[col.columnid]={value:+col.identity.value,step:+col.identity.step};
10025+
// ss.push('\''+col.columnid+'\':(alasql.databases[\''+db.databaseid+'\'].tables[\''
10026+
// +tableid+'\'].identities[\''+col.columnid+'\'].value)');
1002510027
}
1002610028
if(col.check) {
1002710029
table.checkfn.push(new Function("r",'return '+col.check.expression.toJavaScript('r','')));
@@ -10075,7 +10077,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1007510077
// console.log(r, rr, addr);
1007610078
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
1007710079
if(!fktable.uniqs[fktable.pk.hh][addr]) {
10078-
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
10080+
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
1007910081
}
1008010082
return true;
1008110083
};
@@ -10146,7 +10148,8 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1014610148
// console.log(r, rr, addr);
1014710149
// console.log(fktable.uniqs[fktable.pk.hh][addr]);
1014810150
if(!fktable.uniqs[fktable.pk.hh][addr]) {
10149-
throw new Error('Foreign key "'+r[col.columnid]+'" is not found');
10151+
//console.log(228,table,col,fk);
10152+
throw new Error('Foreign key "'+r[col.columnid]+'" is not found in table '+fktable.tableid);
1015010153
}
1015110154
return true;
1015210155
};
@@ -10180,6 +10183,16 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1018010183
// r[ident.columnid] = ident.value;
1018110184
// });
1018210185
// }
10186+
//console.log(262,r);
10187+
//console.log(263,table.identities)
10188+
for(var columnid in table.identities){
10189+
var ident = table.identities[columnid];
10190+
// console.log(ident);
10191+
r[columnid] = ident.value;
10192+
// console.log(ident);
10193+
};
10194+
//console.log(270,r);
10195+
1018310196

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

1021510228
// Final change before insert
1021610229

10230+
10231+
table.data.push(r);
10232+
// Update indices
10233+
10234+
1021710235
for(var columnid in table.identities){
1021810236
var ident = table.identities[columnid];
1021910237
// console.log(ident);
1022010238
ident.value += ident.step;
1022110239
// console.log(ident);
1022210240
};
1022310241

10224-
table.data.push(r);
10225-
// Update indices
10226-
1022710242
if(table.pk) {
1022810243
var pk = table.pk;
1022910244
var addr = pk.onrightfn(r);
@@ -10238,7 +10253,7 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
1023810253

1023910254
};
1024010255

10241-
table.delete = function(i) {
10256+
table.delete = function(i,params,alasql) {
1024210257
var table = this;
1024310258
var r = this.data[i];
1024410259
if(this.pk) {
@@ -11597,7 +11612,7 @@ yy.Insert.prototype.compile = function (databaseid) {
1159711612
s += 'return '+self.values.length;
1159811613
}
1159911614

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

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

1172611741
var newtable = [];
1172711742
for(var i=0, ilen=table.data.length;i<ilen;i++) {
11728-
if(wherefn(table.data[i],params)) {
11743+
if(wherefn(table.data[i],params,alasql)) {
1172911744
// Check for transaction - if it is not possible then return all back
1173011745
if(table.delete) {
11731-
table.delete(i);
11746+
table.delete(i,params,alasql);
1173211747
} else {
1173311748
// SImply do not push
1173411749
}

dist/alasql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/alasql.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)