Skip to content

Commit

Permalink
something
Browse files Browse the repository at this point in the history
  • Loading branch information
agershun committed Apr 1, 2015
2 parents cca8a7f + b7eb835 commit dfafb10
Show file tree
Hide file tree
Showing 24 changed files with 794 additions and 554 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Changelog

### 0.0.43 "The Wall" (25.03.2015 - 01.04.2015)
* Created "develop" branch for git-flow
* Fixed GREATEST and LEAST() bugs
* Added flags {sourcefilename: "aaa", range:"B4"} to INTO XLSX() function
* CREATE TABLE one(two,three) - without coulmn types

### 0.0.42 "Robin" (17.03.2015 - ...03.2015)
### 0.0.42 "Robin" (17.03.2015 - 25.03.2015)
* MAX() and MIN() math functions renamed to GREATEST() and LEAST()
* ORDER BY 2,1
* :: casting operator
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions PEOPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ In English:
* ValueType [Pure JavaScript In-Memory Database](http://valuetype.wordpress.com/2014/11/07/pure-javascript-in-memory-database/)
* SlideShare [Alasql.js fast JavaScript in-memory SQL database](http://www.slideshare.net/AndreyGershun/alasqljsfast-javascript-inmemory-sql-database)
* SlideShare [SQL and NoSQL in Alasql database](http://www.slideshare.net/AndreyGershun/sql-and-nosql-in-alasql)
* Glauco Custódio [Local Storage with AlaSQL in Cordova/Ionic Framework](http://blog.glaucocustodio.com/2015/03/30/local-storage-with-alasql-in-cordovaionic-framework/)


In Chinese
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Alasql.js - JavaScript SQL database library with support of localStorage, IndexedDB, and Excel

Version: 0.0.42 "Robin" Date: March 25, 2015 [Change log](CHANGELOG.md), [Release plan](RELEASES.md)
Version: 0.0.43 "The Wall" Date: April 1, 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.

Expand Down Expand Up @@ -678,14 +678,13 @@ Alasql includess [FileSaver.js](https://github.com/eligrey/FileSaver.js/) librar

### Contributors

* Andrey Gershun
* Mathias Rangel Wulff

* [Andrey Gershun](http://github.com/agershun)
* [Mathias Rangel Wulff](https://github.com/mathiasrw)
* [Aubert Grégoire](https://github.com/gregaubert)

### Credits

Many thanks to Zach Carter for [Jison](http://zaach.github.io/jison/) parser generator, to the author of FileSaver.js,
Andrew Kent for his [SQL Parser](https://github.com/forward/sql-parser),
Many thanks to Zach Carter for [Jison](http://zaach.github.io/jison/) parser generator, to the author of FileSaver.js, Andrew Kent for his [SQL Parser](https://github.com/forward/sql-parser),
authors of [XLSX](https://github.com/SheetJS/js-xlsx) library,
and other people for useful tools, which make our work much easier.

Expand Down
403 changes: 227 additions & 176 deletions alasql.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion alasql.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions alasql.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions console/alasql.min.js

Large diffs are not rendered by default.

403 changes: 227 additions & 176 deletions dist/alasql.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/alasql.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/alasql.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alasql",
"description": "Alasql - JavaScript SQL database and data manipulation library",
"version": "0.0.42",
"version": "0.0.43",
"author": "Andrey Gershun <[email protected]>",
"directories": {
"example": "examples",
Expand Down
4 changes: 2 additions & 2 deletions src/10start.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// alasql.js
// Alasql - JavaScript SQL database
// Date: 25.03.2015
// Version: 0.0.42
// Date: 01.04.2015
// Version: 0.0.43
// (ñ) 2014, Andrey Gershun
//

Expand Down
11 changes: 9 additions & 2 deletions src/55functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ stdlib.LOWER = stdlib.LCASE = function(s) {return '('+s+').toLowerCase()';}


// LTRIM
stdlib.GREATEST = function(){return 'Math.max('+arguments.join(',')+')'};
stdlib.LEAST = function(){return 'Math.min('+arguments.join(',')+')'};

stdlib.GREATEST = function(){
return 'Math.max('+Array.prototype.join.call(arguments, ',')+')'
};

stdlib.LEAST = function(){
return 'Math.min('+Array.prototype.join.call(arguments, ',')+')'
};

stdlib.MID = function(a,b,c){
if(arguments.length == 2) return '('+a+').substr('+b+'-1)';
else if(arguments.length == 3) return '('+a+').substr('+b+'-1,'+c+')';
Expand Down
129 changes: 85 additions & 44 deletions src/83into.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,57 +207,98 @@ alasql.into.XLSX = function(filename, opts, data, columns, cb) {
alasql.utils.extend(opt, opts);

var res = data.length;
var cells = {};

var wb = {SheetNames:[], Sheets:{}};
wb.SheetNames.push(opt.sheetid);
wb.Sheets[opt.sheetid] = cells;

wb.Sheets[opt.sheetid]['!ref'] = 'A1:'+alasql.utils.xlsnc(columns.length)+(data.length+2);
var i = 1;
// Check overwrite flag
if(opt.sourcefilename) {
alasql.utils.loadBinaryFile(opt.sourcefilename,!!cb,function(data){
wb = XLSX.read(data,{type:'binary'});
doExport();
});
} else {
doExport();
};

function doExport() {
var cells = {};

if(opt.headers) {
columns.forEach(function(col, idx){
cells[alasql.utils.xlsnc(idx)+""+i] = {v:col.columnid};
});
i++;
}
if(wb.SheetNames.indexOf(opt.sheetid) > -1) {
cells = wb.Sheets[opt.sheetid];
} else {
wb.SheetNames.push(opt.sheetid);
wb.Sheets[opt.sheetid] = {};
cells = wb.Sheets[opt.sheetid];
}

for(var j=0;j<data.length;j++) {
columns.forEach(function(col, idx){
cells[alasql.utils.xlsnc(idx)+""+i] = {v:data[j][col.columnid]};
});
i++;
}
var range = "A1";
if(opt.range) range = opt.range;

// console.log(wb);
var col0 = alasql.utils.xlscn(range.match(/[A-Z]+/)[0]);
var row0 = +range.match(/[0-9]+/)[0]-1;

if(typeof exports == 'object') {
XLSX.writeFile(wb, filename);
} else {
//console.log(wb);
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };
var wbout = XLSX.write(wb,wopts);

function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
if(wb.Sheets[opt.sheetid]['!ref']) {
var rangem = wb.Sheets[opt.sheetid]['!ref'];
var colm = alasql.utils.xlscn(rangem.match(/[A-Z]+/)[0]);
var rowm = +rangem.match(/[0-9]+/)[0]-1;
} else {
var colm = 1, rowm = 1;
}
/* the saveAs call downloads a file on the local machine */
// saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), '"'+filename+'"')
// saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), filename)
// saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.ms-excel"}), '"'+filename+'"');
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), filename);
}
var colmax = Math.max(col0+columns.length,colm);
var rowmax = Math.max(row0+data.length+2,rowm);

// console.log(col0,row0);
var i = row0+1;

// data.forEach(function(d){
// s += columns.map(function(col){
// return d[col.columnid];
// }).join(opts.separator)+'\n';
// });
// alasql.utils.saveFile(filename,s);
if(cb) res = cb(res);
return res;
wb.Sheets[opt.sheetid]['!ref'] = 'A1:'+alasql.utils.xlsnc(colmax)+(rowmax);
// var i = 1;

if(opt.headers) {
columns.forEach(function(col, idx){
cells[alasql.utils.xlsnc(col0+idx)+""+i] = {v:col.columnid};
});
i++;
}

for(var j=0;j<data.length;j++) {
columns.forEach(function(col, idx){
cells[alasql.utils.xlsnc(col0+idx)+""+i] = {v:data[j][col.columnid]};
});
i++;
}

// console.log(wb);
// console.log(wb);

if(typeof exports == 'object') {
XLSX.writeFile(wb, filename);
} else {
//console.log(wb);
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };
var wbout = XLSX.write(wb,wopts);

function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
/* the saveAs call downloads a file on the local machine */
// saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), '"'+filename+'"')
// saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), filename)
// saveAs(new Blob([s2ab(wbout)],{type:"application/vnd.ms-excel"}), '"'+filename+'"');
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), filename);
}


// data.forEach(function(d){
// s += columns.map(function(col){
// return d[col.columnid];
// }).join(opts.separator)+'\n';
// });
// alasql.utils.saveFile(filename,s);
if(cb) res = cb(res);
return res;

};
};
4 changes: 2 additions & 2 deletions src/84from.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ function XLSXLSX(X,filename, opts, cb, idx, query) {
};
var rg = range.split(':');
var col0 = rg[0].match(/[A-Z]+/)[0];
var row0 = rg[0].match(/[0-9]+/)[0];
var row0 = +rg[0].match(/[0-9]+/)[0];
var col1 = rg[1].match(/[A-Z]+/)[0];
var row1 = rg[1].match(/[0-9]+/)[0];
var row1 = +rg[1].match(/[0-9]+/)[0];
// console.log(114,rg,col0,col1,row0,row1);
// console.log(114,rg,alasql.utils.xlscn(col0),alasql.utils.xlscn(col1));

Expand Down
2 changes: 2 additions & 0 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,8 @@ ColumnDef
{ $$ = new yy.ColumnDef({columnid:$1}); yy.extend($$,$2); yy.extend($$,$3);}
| Literal ColumnConstraints
{ $$ = new yy.ColumnDef({columnid:$1}); yy.extend($$,$2); }
| Literal
{ $$ = new yy.ColumnDef({columnid:$1, dbtypeid: ''}); }
;

ColumnType
Expand Down
255 changes: 129 additions & 126 deletions src/alasqlparser.js

Large diffs are not rendered by default.

Binary file modified test/test169a.xlsx
Binary file not shown.
Binary file modified test/test238b.xlsx
Binary file not shown.
32 changes: 32 additions & 0 deletions test/test250.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if(typeof exports === 'object') {
var assert = require("assert");
var alasql = require('../alasql.js');
} else {
__dirname = '.';
};


describe('Test 250 Index problem', function() {

it('1. IN ()',function(done){

alasql(function(){/*
CREATE TABLE tab0(pk INTEGER NOT NULL PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT);
INSERT INTO tab0 VALUES(0,6,4.67,'wdbsg',4,2.89,'altmp');
CREATE TABLE tab1(pk INTEGER NOT NULL PRIMARY KEY, col0 INTEGER, col1 FLOAT, col2 TEXT, col3 INTEGER, col4 FLOAT, col5 TEXT);
CREATE INDEX idx_tab1_4 on tab1 (col4);
INSERT INTO tab1 SELECT * FROM tab0;
DELETE FROM tab1 WHERE col4 > 2.27;
*/});

var res = alasql('SELECT * from tab1');
console.log(res);


// assert(res == false);

done();
});

});

23 changes: 23 additions & 0 deletions test/test251.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if(typeof exports === 'object') {
var assert = require("assert");
var alasql = require('../alasql.js');
} else {
__dirname = '.';
};


describe('Test 251 Overwrite XLSX file', function() {

it('1. Overwrite',function(done){

alasql('SELECT HOUR(NOW()), MINUTE(NOW()), SECOND(NOW()) \
INTO XLSX("test251.xlsx",{sourcefilename:"test251.xlsx", \
sheetid:"test2", range:"B3"})',[],function(res){
assert(res == 1);
done();
});

});

});

Binary file added test/test251.xlsx
Binary file not shown.
25 changes: 25 additions & 0 deletions test/test252.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if(typeof exports === 'object') {
var assert = require("assert");
var alasql = require('../alasql.js');
} else {
__dirname = '.';
};


describe('Test 252 CREATE TABLE without column types', function() {

it('1. Overwrite',function(done){

alasql('CREATE DATABASE test252; USE test252;');
alasql('CREATE TABLE sqlite_sequence(name,seq)');
alasql('INSERT INTO sqlite_sequence VALUES (1,10)');
alasql('INSERT INTO sqlite_sequence VALUES ("one","ten")');
var res = alasql('SELECT * FROM sqlite_sequence');
// console.log(res);

assert.deepEqual(res,[ { name: 1, seq: 10 }, { name: 'one', seq: 'ten' } ]);
done();
});

});

0 comments on commit dfafb10

Please sign in to comment.