Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Alasql fast JavaScript in-memory SQL database

3.365 Aufrufe

Veröffentlicht am

Presentation of Alasql.js library - fast JavaScript in-memory SQL database

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Alasql fast JavaScript in-memory SQL database

  1. 1. Alasql.js fast JavaScript in-memory SQL database ANDREY GERSHUN © 2014
  2. 2. SQL in JavaScript… Warum?  Fast client side data processing for BI and ERP applications  For mobile applications (if there is weak connection to server)  Advanced data filtering and grouping (as alternative to simple .filter() function)  Alternatives  WebSQL – to be depreciated  SQL.js –big and slow  Others: NoSQL or linq clones with many limitations, rather than standard SQL functionality
  3. 3. Alasql advantages  All standard SQL operators and functions with advanced functionality  Fast  Compilation  Queries optimization  Indexation  “Fast” JavaScript  Compact  minimized version is about 100kb) Benchmarks:  http://jsperf.com/alasql-js-vs-websql  http://jsperf.com/sql-js-vs-alasql-js/4  http://jsperf.com/alasql-vs-lodash-sort/3
  4. 4. Alasql functionality  Standard SQL operators:  SELECT, INSERT, DELETE, UPDATE  CREATE/ALTER/DROP TABLE  CREATE/USE/DROP DATABASE  Full SELECT syntax, including  LEFT/RIGHT/OUTER/CROSS JOINS  EXISTS, IN, ALL/SOME  DISTINCT / INTO / GROUP BY / HAVING / ORDER BY / LIMIT  UNION/INTERSECT/EXCLUDE  Subqueries Advanced GROUP BY options  CUBE, ROLLUP, GROUPING SETS Functions  ABS(), IIF(), IFNULL(), INSTR(), LOWER(), UPPER(), LCASE(), UCASE(), LEN(), LENGTH() Aggregators  SUM/COUNT/MIN/MAX/FIRST/LAST
  5. 5. Alasql in browser In browser <script src=‘alasql.js’></script> <script> alasql(‘CREATE TABLE one (a INT)’); alasql(‘INSERT INTO one VALUES (?)’,[10]); var res = alasql.value(‘SELECT SUM(a) FROM one’)); </script> As AMD module require([‘alasql’], function(alasql) { alasql(‘CREATE TABLE one (a INT)’); alasql(‘INSERT INTO one VALUES (?)’,[10]); var res = alasql.value(‘SELECT SUM(a) FROM one’); } In Node.js Installation npm install alasql Usage var alasql = require(‘alasql’); alasql(‘CREATE TABLE one (a INT)’); alasql(‘INSERT INTO one VALUES (?)’,[10]); var res = alasql.value(‘SELECT SUM(a) FROM one’);
  6. 6. SQL and JavaScript: Better Together SQL way alasql(‘CREATE DATABASE test01’); alasql(‘USE test01’); alasql(‘CREATE TABLE one (a INT)’); alasql(‘INSERT INTO one VALUES (10)’): var res = alasql(‘SELECT * FROM one’); JavaScript way data = [{a:1}, {a:2}, {a:3}]; alasql(‘SELECT * FROM ? WHERE a >= ?’, [data, 2]); or var db = new alasql.Database(); db.exec(“select * from one”, function(data){ console.log(data.length); });
  7. 7. User-defined functions and compiled statements Custom functions: alasql.fn.myfn = function(a,b) { return a*b+1; } alasql(‘SELECT myfn(a,b) FROM one’); Compiled statements: var ins = alasql.compile(‘INSERT INTO one VALUES (?,?)’); ins(1,10); ins(2,20); Compiled functions: var bigSum = alasql.compile(‘SELECT SUM(a) FROM one WHERE a>3’, ‘value’); var res = bigSum([10]) + 10;
  8. 8. Where to find Alasql.js? Alasql.js at Github:  https://github.com/agershun/alasql Official web-site:  http://alasql.org

×