-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.44", | ||
"version": "0.0.45", | ||
"author": "Andrey Gershun <[email protected]>", | ||
"directories": { | ||
"example": "examples", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
|
||
/** | ||
UMD envelope | ||
*/ | ||
|
||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define([], factory); | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
} else { | ||
root.alasql = factory(); | ||
} | ||
}(this, function () { | ||
|
||
/** | ||
alasql - Main Alasql class | ||
@param {string | Object} sql SQL-statement or data object for fuent interface | ||
@param {Object} params SQL parameters | ||
@param {Function} cb callback function | ||
@param {Object} scope Scope for nested queries | ||
@return {array} Result data object | ||
Standard sync call: | ||
alasql('CREATE TABLE one'); | ||
Query: | ||
var res = alasql('SELECT * FROM one'); | ||
Call with parameters: | ||
var res = alasql('SELECT * FROM ?',[data]); | ||
Standard async call with callback function: | ||
alasql('SELECT * FROM ?',[data],function(res){ | ||
console.log(data); | ||
}); | ||
Call with scope for subquery (to pass common values): | ||
var scope = {one:{a:2,b;20}} | ||
alasql('SELECT * FROM ? two WHERE two.a = one.a',[data],null,scope); | ||
Call for fluent interface with data object: | ||
alasql(data).Where(function(x){return x.a == 10}).exec(); | ||
Call for fluent interface without data object: | ||
alasql().From(data).Where(function(x){return x.a == 10}).exec(); | ||
*/ | ||
|
||
var alasql = function(sql, params, cb, scope) { | ||
if(typeof importScripts != 'function' && alasql.webworker) { | ||
var id = alasql.lastid++; | ||
alasql.buffer[id] = cb; | ||
alasql.webworker.postMessage({id:id,sql:sql,params:params}); | ||
} else { | ||
if(arguments.length == 0) { | ||
// Without arguments - Fluent interface | ||
return new yy.Select({ | ||
columns:[new yy.Column({columnid:'*'})], | ||
from: [new yy.ParamValue({param:0})] | ||
}); | ||
} else if (arguments.length == 1 && typeof sql == "object" && sql instanceof Array) { | ||
// One argument data object - fluent interface | ||
var select = new yy.Select({ | ||
columns:[new yy.Column({columnid:'*'})], | ||
from: [new yy.ParamValue({param:0})] | ||
}); | ||
select.preparams = [sql]; | ||
return select; | ||
} else { | ||
// Standard interface | ||
// alasql('#sql'); | ||
if(typeof sql == 'string' && sql[0]=='#' && typeof document == "object") { | ||
sql = document.querySelector(sql).textContent; | ||
} else if(typeof sql == 'object' && sql instanceof HTMElement) { | ||
sql = sql.textContent; | ||
} else if(typeof sql == 'function') { | ||
// to run multiline functions | ||
sql = sql.toString().slice(14,-3); | ||
} | ||
// Run SQL | ||
return alasql.exec(sql, params, cb, scope); | ||
} | ||
}; | ||
}; | ||
|
||
/** Current version of alasql */ | ||
alasql.version = "0.0.44"; | ||
|
||
/** | ||
UMD envelope | ||
*/ | ||
|
||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define([], factory); | ||
} else if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
} else { | ||
root.alasql = factory(); | ||
} | ||
}(this, function () { | ||
|
||
/** | ||
alasql - Main Alasql class | ||
@param {string | Object} sql SQL-statement or data object for fuent interface | ||
@param {Object} params SQL parameters | ||
@param {Function} cb callback function | ||
@param {Object} scope Scope for nested queries | ||
@return {array} Result data object | ||
Standard sync call: | ||
alasql('CREATE TABLE one'); | ||
Query: | ||
var res = alasql('SELECT * FROM one'); | ||
Call with parameters: | ||
var res = alasql('SELECT * FROM ?',[data]); | ||
Standard async call with callback function: | ||
alasql('SELECT * FROM ?',[data],function(res){ | ||
console.log(data); | ||
}); | ||
Call with scope for subquery (to pass common values): | ||
var scope = {one:{a:2,b;20}} | ||
alasql('SELECT * FROM ? two WHERE two.a = one.a',[data],null,scope); | ||
Call for fluent interface with data object: | ||
alasql(data).Where(function(x){return x.a == 10}).exec(); | ||
Call for fluent interface without data object: | ||
alasql().From(data).Where(function(x){return x.a == 10}).exec(); | ||
*/ | ||
|
||
var alasql = function(sql, params, cb, scope) { | ||
if(typeof importScripts != 'function' && alasql.webworker) { | ||
var id = alasql.lastid++; | ||
alasql.buffer[id] = cb; | ||
alasql.webworker.postMessage({id:id,sql:sql,params:params}); | ||
} else { | ||
if(arguments.length == 0) { | ||
// Without arguments - Fluent interface | ||
return new yy.Select({ | ||
columns:[new yy.Column({columnid:'*'})], | ||
from: [new yy.ParamValue({param:0})] | ||
}); | ||
} else if (arguments.length == 1 && typeof sql == "object" && sql instanceof Array) { | ||
// One argument data object - fluent interface | ||
var select = new yy.Select({ | ||
columns:[new yy.Column({columnid:'*'})], | ||
from: [new yy.ParamValue({param:0})] | ||
}); | ||
select.preparams = [sql]; | ||
return select; | ||
} else { | ||
// Standard interface | ||
// alasql('#sql'); | ||
if(typeof sql == 'string' && sql[0]=='#' && typeof document == "object") { | ||
sql = document.querySelector(sql).textContent; | ||
} else if(typeof sql == 'object' && sql instanceof HTMElement) { | ||
sql = sql.textContent; | ||
} else if(typeof sql == 'function') { | ||
// to run multiline functions | ||
sql = sql.toString().slice(14,-3); | ||
} | ||
// Run SQL | ||
return alasql.exec(sql, params, cb, scope); | ||
} | ||
}; | ||
}; | ||
|
||
/** Current version of alasql */ | ||
alasql.version = "0.0.45"; | ||
|