From 079a9cfc2f0e2508cb0f3b92496cc960cf9e9d37 Mon Sep 17 00:00:00 2001 From: Derek Ekins Date: Fri, 17 Feb 2017 20:24:02 +0000 Subject: [PATCH 1/7] implemented basiscs of websql driver --- index.js | 4 +- package.json | 3 +- test/websqlSpec.js | 81 ++++++++++++++++++++++++++++++++++++++++ websqlDriver.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 test/websqlSpec.js create mode 100644 websqlDriver.js diff --git a/index.js b/index.js index 2b74eae..8c03e99 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var pgDriver = require("./pgDriver"); var mysqlDriver = require("./mysqlDriver"); var oracleDriver = require("./oracleDriver"); var sqliteDriver = require("./sqliteDriver"); +var websqlDriver = require("./websqlDriver"); var debug = require("debug")("sworm"); var debugResults = require("debug")("sworm:results"); var redactConfig = require('./redactConfig'); @@ -438,7 +439,8 @@ exports.db = function(config) { pg: pgDriver, mysql: mysqlDriver, oracle: oracleDriver, - sqlite: sqliteDriver + sqlite: sqliteDriver, + websql: websqlDriver }[this.config.driver]; if (!driver) { diff --git a/package.json b/package.json index 5dd1619..723b442 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "mssql": "3.3.0", "mysql": "2.11.1", "pg": "6.1.0", - "sqlite3": "3.1.8" + "sqlite3": "3.1.8", + "websql": "0.4.4" }, "scripts": { "test": "mocha" diff --git a/test/websqlSpec.js b/test/websqlSpec.js new file mode 100644 index 0000000..136755c --- /dev/null +++ b/test/websqlSpec.js @@ -0,0 +1,81 @@ +var describeDatabase = require('./describeDatabase'); +var expect = require('chai').expect; +var sworm = require('..'); + +var database = { + createTables: function(db, tables) { + function createTable(name, sql) { + tables.push(name); + return db.query(sql); + } + + return createTable("people", + 'create table if not exists people (id integer primary key, name varchar(50) NOT NULL, address_id integer NULL, photo blob null)' + ).then(function() { + return createTable("people_addresses", + 'create table if not exists people_addresses(address_id integer NOT NULL, person_id integer NOT NULL, rating integer NULL)' + ); + }).then(function() { + return createTable("addresses", + 'create table if not exists addresses(id integer primary key, address varchar(50) NOT NULL)' + ); + }).then(function() { + return createTable("people_weird_id", + 'create table if not exists people_weird_id(weird_id integer primary key, name varchar(50) NULL, address_weird_id integer NULL)' + ); + }).then(function() { + return createTable("people_explicit_id", + 'create table if not exists people_explicit_id(id integer NOT NULL, name varchar(50) NOT NULL)' + ); + }); + }, + + "true": 1, + "false": 0, + + clean: function(records) { + return records; + }, + + driverModuleName: "websql" +}; + +var config = { + driver: "websql", + config: { filename: __dirname + "/test.db" } +}; + +describeDatabase("websql", config, database, function () { + describe('options', function () { + it('can pass options to query', function () { + var db = sworm.db(config); + + return db.query('drop table if exists blah').then(function () { + return db.query( + "create table blah ( x integer not null, y integer not null ); " + + "insert into blah (x, y) values (1, 2); " + + "insert into blah (x, y) values (2, 3); " + , {}, {multiline: true}); + }).then(function () { + return db.query('select * from blah').then(function (rows) { + expect(rows).to.eql([ + { x: 1, y: 2 }, + { x: 2, y: 3 } + ]); + }); + }); + }); + }); + + describe('connection', function () { + it('can accept a file: URL', function () { + var db = sworm.db('file://' + config.config.filename + '?asdf=asdf'); + return db.query('select * from people') + }); + + it('can accept a filename', function () { + var db = sworm.db(config.config.filename); + return db.query('select * from people') + }); + }); +}); diff --git a/websqlDriver.js b/websqlDriver.js new file mode 100644 index 0000000..df43c34 --- /dev/null +++ b/websqlDriver.js @@ -0,0 +1,93 @@ +var promisify = require('./promisify'); +var optionalRequire = require("./optionalRequire"); +var debug = require('debug')('sworm:websql'); +var paramRegex = require('./paramRegex') +var urlUtils = require('url') + +module.exports = function() { + var openDatabase = optionalRequire('websql'); + + return { + query: function(query, params, options) { + var self = this; + var paramList = [] + + if (params) { + query = query.replace(paramRegex, function(_, paramName) { + if (!params.hasOwnProperty(paramName)) { + throw new Error('no such parameter @' + paramName); + } else { + paramList.push(params[paramName]); + } + return '?'; + }); + } + + if (options.statement || options.insert) { + return new Promise(function (fulfil, reject) { + debug(query, paramList); + console.log(query, paramList); + self.connection.transaction(function(tx) { + tx.executeSql(query, paramList, function(tx, result){ + fulfil({id: result.insertId, changes: this.changes}); + }, function(tx, error){ + console.log('err', error) + reject(error) + }); + }); + }); + } else if (options.exec || options.multiline) { + return promisify(function (cb) { + debug(query, paramList); + self.connection.exec(query, [], cb); + }); + } else { + return new Promise(function(fulfil, reject) { + debug(query, paramList); + self.connection.transaction(function(tx) { + tx.executeSql(query, paramList, function(tx, result){ + fulfil(result.rows._array) + }, function(tx, error){ + console.log('err', error) + reject(error) + }); + }); + }); + } + }, + + insert: function(query, params, options) { + return this.query(query, params, options) + }, + + connect: function(options) { + var config = parseConfig(options) + var defaultSize = 5 * 1024 * 1024; + this.connection = openDatabase(config.filename, '1.0', config.description, config.size || defaultSize) + + return Promise.resolve() + }, + + close: function() { + return Promise.resolve() + } + }; +}; + +function parseConfig(options) { + if (options.url) { + var url = urlUtils.parse(options.url) + + if (url.protocol) { + return { + filename: url.pathname + } + } else { + return { + filename: options.url + } + } + } else { + return options.config + } +} From c4080644ef92526abc97ffc6d015d47566b6e3ba Mon Sep 17 00:00:00 2001 From: Tim Macfarlane Date: Mon, 20 Feb 2017 09:25:02 +0100 Subject: [PATCH 2/7] fixed tests, no (async) transactions... :( --- test/describeDatabase.js | 214 ++++++++++++++++++++------------------- test/websqlSpec.js | 25 +---- websqlDriver.js | 55 +++++----- 3 files changed, 142 insertions(+), 152 deletions(-) diff --git a/test/describeDatabase.js b/test/describeDatabase.js index 53c2793..39e46b7 100644 --- a/test/describeDatabase.js +++ b/test/describeDatabase.js @@ -193,116 +193,129 @@ module.exports = function(name, config, database, otherTests) { }); }); - describe('transactions', function () { - beforeEach(function () { - if (database.setAutoCommit) { - database.setAutoCommit(false); - } - }); + if (!database.hasOwnProperty('transactions') || database.transactions != false) { + describe('transactions', function () { + beforeEach(function () { + if (database.setAutoCommit) { + database.setAutoCommit(false); + } + }); - afterEach(function () { - if (database.setAutoCommit) { - database.setAutoCommit(true); - } - }); + afterEach(function () { + if (database.setAutoCommit) { + database.setAutoCommit(true); + } + }); - describe('rollback', function () { - describe('explicit', function () { - it('rolls back when rollback is called', function () { - return db.begin().then(function () { - var bob = person({ name: 'bob' }); - return bob.save().then(function () { - return db.query('select * from people'); - }).then(function (people) { - expect(people).to.eql([ - { - id: bob.id, - name: 'bob', - address_id: null, - photo: null - } - ]); - }).then(function() { - return db.rollback(); - }).then(function() { - return db.query('select * from people'); - }).then(function(people) { - expect(people).to.eql([ - ]); + describe('rollback', function () { + describe('explicit', function () { + it('rolls back when rollback is called', function () { + return db.begin().then(function () { + var bob = person({ name: 'bob' }); + return bob.save().then(function () { + return db.query('select * from people'); + }).then(function (people) { + expect(people).to.eql([ + { + id: bob.id, + name: 'bob', + address_id: null, + photo: null + } + ]); + }).then(function() { + return db.rollback(); + }).then(function() { + return db.query('select * from people'); + }).then(function(people) { + expect(people).to.eql([ + ]); + }); }); }); }); - }); - describe('scoped', function () { - it('rolls back if the transaction scope throws an exception', function () { - return expect(db.transaction(function () { - var bob = person({ name: 'bob' }); - return bob.save().then(function() { + describe('scoped', function () { + it('rolls back if the transaction scope throws an exception', function () { + return expect(db.transaction(function () { + var bob = person({ name: 'bob' }); + return bob.save().then(function() { + return db.query('select * from people'); + }).then(function(people) { + expect(people).to.eql([ + { + id: bob.id, + name: 'bob', + address_id: null, + photo: null + } + ]); + + throw new Error('uh oh'); + }); + })).to.be.rejectedWith('uh oh').then(function() { return db.query('select * from people'); }).then(function(people) { expect(people).to.eql([ - { - id: bob.id, - name: 'bob', - address_id: null, - photo: null - } ]); - - throw new Error('uh oh'); }); - })).to.be.rejectedWith('uh oh').then(function() { - return db.query('select * from people'); - }).then(function(people) { - expect(people).to.eql([ - ]); }); }); }); - }); - describe('commit', function () { - describe('explicit', function () { - it('makes changes after commit is called', function () { - return db.begin().then(function () { - var bob = person({ name: 'bob' }); - return bob.save().then(function() { - return db.query('select * from people'); - }).then(function(people) { - expect(people).to.eql([ - { - id: bob.id, - name: 'bob', - address_id: null, - photo: null - } - ]); - }).then(function() { - return db.commit(); - }).then(function() { - return db.query('select * from people'); - }).then(function(people) { - expect(people).to.eql([ - { - id: bob.id, - name: 'bob', - address_id: null, - photo: null - } - ]); + describe('commit', function () { + describe('explicit', function () { + it('makes changes after commit is called', function () { + return db.begin().then(function () { + var bob = person({ name: 'bob' }); + return bob.save().then(function() { + return db.query('select * from people'); + }).then(function(people) { + expect(people).to.eql([ + { + id: bob.id, + name: 'bob', + address_id: null, + photo: null + } + ]); + }).then(function() { + return db.commit(); + }).then(function() { + return db.query('select * from people'); + }).then(function(people) { + expect(people).to.eql([ + { + id: bob.id, + name: 'bob', + address_id: null, + photo: null + } + ]); + }); }); }); }); - }); - describe('scoped', function () { - it('makes changes after commit is called', function () { - var bob; + describe('scoped', function () { + it('makes changes after commit is called', function () { + var bob; - return db.transaction(function () { - bob = person({ name: 'bob' }); - return bob.save().then(function() { + return db.transaction(function () { + bob = person({ name: 'bob' }); + return bob.save().then(function() { + return db.query('select * from people'); + }).then(function(people) { + expect(people).to.eql([ + { + id: bob.id, + name: 'bob', + address_id: null, + photo: null + } + ]); + }); + }).then(function() { return db.query('select * from people'); }).then(function(people) { expect(people).to.eql([ @@ -314,22 +327,19 @@ module.exports = function(name, config, database, otherTests) { } ]); }); - }).then(function() { - return db.query('select * from people'); - }).then(function(people) { - expect(people).to.eql([ - { - id: bob.id, - name: 'bob', - address_id: null, - photo: null - } - ]); }); }); }); }); - }); + } else { + describe('no transactions', function () { + it('throws when asked to create a new transaction', function () { + expect(function () { + db.begin() + }).to.throw('transactions are not supported') + }) + }) + } describe("concurrency", function() { it("can insert multiple rows, maintaining correct IDs", function() { diff --git a/test/websqlSpec.js b/test/websqlSpec.js index 136755c..b6bd3f8 100644 --- a/test/websqlSpec.js +++ b/test/websqlSpec.js @@ -37,7 +37,9 @@ var database = { return records; }, - driverModuleName: "websql" + driverModuleName: "websql", + + transactions: false }; var config = { @@ -46,27 +48,6 @@ var config = { }; describeDatabase("websql", config, database, function () { - describe('options', function () { - it('can pass options to query', function () { - var db = sworm.db(config); - - return db.query('drop table if exists blah').then(function () { - return db.query( - "create table blah ( x integer not null, y integer not null ); " + - "insert into blah (x, y) values (1, 2); " + - "insert into blah (x, y) values (2, 3); " - , {}, {multiline: true}); - }).then(function () { - return db.query('select * from blah').then(function (rows) { - expect(rows).to.eql([ - { x: 1, y: 2 }, - { x: 2, y: 3 } - ]); - }); - }); - }); - }); - describe('connection', function () { it('can accept a file: URL', function () { var db = sworm.db('file://' + config.config.filename + '?asdf=asdf'); diff --git a/websqlDriver.js b/websqlDriver.js index df43c34..344a5de 100644 --- a/websqlDriver.js +++ b/websqlDriver.js @@ -23,37 +23,20 @@ module.exports = function() { }); } - if (options.statement || options.insert) { - return new Promise(function (fulfil, reject) { - debug(query, paramList); - console.log(query, paramList); - self.connection.transaction(function(tx) { - tx.executeSql(query, paramList, function(tx, result){ - fulfil({id: result.insertId, changes: this.changes}); - }, function(tx, error){ - console.log('err', error) - reject(error) - }); - }); - }); - } else if (options.exec || options.multiline) { - return promisify(function (cb) { - debug(query, paramList); - self.connection.exec(query, [], cb); - }); - } else { - return new Promise(function(fulfil, reject) { - debug(query, paramList); - self.connection.transaction(function(tx) { - tx.executeSql(query, paramList, function(tx, result){ + return new Promise(function (fulfil, reject) { + debug(query, paramList); + self.connection.transaction(function(tx) { + tx.executeSql(query, paramList, function(tx, result){ + if (options.statement || options.insert) { + fulfil({id: result.insertId, changes: result.rowsAffected}); + } else { fulfil(result.rows._array) - }, function(tx, error){ - console.log('err', error) - reject(error) - }); + } + }, function(tx, error){ + reject(error) }); }); - } + }); }, insert: function(query, params, options) { @@ -70,6 +53,22 @@ module.exports = function() { close: function() { return Promise.resolve() + }, + + noTransactions: function () { + throw new Error('transactions are not supported with websql') + }, + + begin: function () { + this.noTransactions() + }, + + commit: function () { + this.noTransactions() + }, + + rollback: function () { + this.noTransactions() } }; }; From e19e000505391bbf1554b530b91555ee6fc19c97 Mon Sep 17 00:00:00 2001 From: Derek Ekins Date: Wed, 22 Feb 2017 17:15:30 +0000 Subject: [PATCH 3/7] use websql api to access result set instead of just grabbing the _array property - this doesn't exist in a real websql implementation --- websqlDriver.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/websqlDriver.js b/websqlDriver.js index 344a5de..3c2784e 100644 --- a/websqlDriver.js +++ b/websqlDriver.js @@ -30,7 +30,11 @@ module.exports = function() { if (options.statement || options.insert) { fulfil({id: result.insertId, changes: result.rowsAffected}); } else { - fulfil(result.rows._array) + var results = [] + for (var i = 0; i Date: Wed, 22 Feb 2017 20:51:32 +0000 Subject: [PATCH 4/7] websql option to supply openDatabase function, this allows you to use websql without having the websql module but instead grabbing window.openDatabase from the browser --- test/websqlSpec.js | 23 +++++++++++++++++++++++ websqlDriver.js | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/websqlSpec.js b/test/websqlSpec.js index b6bd3f8..5f67e92 100644 --- a/test/websqlSpec.js +++ b/test/websqlSpec.js @@ -58,5 +58,28 @@ describeDatabase("websql", config, database, function () { var db = sworm.db(config.config.filename); return db.query('select * from people') }); + + context('openDatabase option', function () { + it('can provide a custom openDatabase implementation that doesnt work', function () { + var db = sworm.db({ + driver: 'websql', + config: {}, + openDatabase: function () { + throw new Error('openDatabase called') + }}) + + expect(db.connect.bind(db)).to.throw('openDatabase called') + }) + + it('can provide a working custom openDatabase implementation', function () { + var db = sworm.db({ + driver: 'websql', + config: config.config, + openDatabase: require('websql') + }) + + return db.query('select * from people') + }) + }) }); }); diff --git a/websqlDriver.js b/websqlDriver.js index 3c2784e..0e075a9 100644 --- a/websqlDriver.js +++ b/websqlDriver.js @@ -5,8 +5,6 @@ var paramRegex = require('./paramRegex') var urlUtils = require('url') module.exports = function() { - var openDatabase = optionalRequire('websql'); - return { query: function(query, params, options) { var self = this; @@ -48,6 +46,7 @@ module.exports = function() { }, connect: function(options) { + var openDatabase = options.openDatabase || optionalRequire('websql') var config = parseConfig(options) var defaultSize = 5 * 1024 * 1024; this.connection = openDatabase(config.filename, '1.0', config.description, config.size || defaultSize) From ce1ac69ae310b23d1ad7d46fee3f88bea3bf584f Mon Sep 17 00:00:00 2001 From: Tim Macfarlane Date: Mon, 13 Mar 2017 15:15:25 +0100 Subject: [PATCH 5/7] websql: running tests in electron-mocha * fixed failing tests * removed websql module, as we now test exclusively in the browser --- index.js | 4 ++- package.json | 7 ++-- test/{ => browser}/websqlSpec.js | 60 ++++++++++++++++---------------- test/describeDatabase.js | 28 ++++++++------- websqlDriver.js | 22 ++++++++---- 5 files changed, 67 insertions(+), 54 deletions(-) rename test/{ => browser}/websqlSpec.js (57%) diff --git a/index.js b/index.js index 8c03e99..c9b7a12 100644 --- a/index.js +++ b/index.js @@ -549,8 +549,10 @@ exports.escape = function(value) { } function configFromUrl(url) { + var isBrowser = typeof window !== 'undefined' + var parsedUrl = urlUtils.parse(url) - var protocol = parsedUrl.protocol? parsedUrl.protocol.replace(/:$/, ''): 'sqlite' + var protocol = parsedUrl.protocol? parsedUrl.protocol.replace(/:$/, ''): (isBrowser? 'websql': 'sqlite') var driver = { postgres: 'pg', file: 'sqlite' diff --git a/package.json b/package.json index 723b442..7436a78 100644 --- a/package.json +++ b/package.json @@ -14,17 +14,18 @@ "devDependencies": { "chai": "3.5.0", "chai-as-promised": "5.3.0", + "electron": "1.6.2", + "electron-mocha": "3.3.0", "es6-promise": "3.2.1", "fs-promise": "0.5.0", "mocha": "2.5.3", "mssql": "3.3.0", "mysql": "2.11.1", "pg": "6.1.0", - "sqlite3": "3.1.8", - "websql": "0.4.4" + "sqlite3": "3.1.8" }, "scripts": { - "test": "mocha" + "test": "mocha && electron-mocha --renderer test/browser" }, "repository": { "type": "git", diff --git a/test/websqlSpec.js b/test/browser/websqlSpec.js similarity index 57% rename from test/websqlSpec.js rename to test/browser/websqlSpec.js index 5f67e92..d434853 100644 --- a/test/websqlSpec.js +++ b/test/browser/websqlSpec.js @@ -1,6 +1,6 @@ -var describeDatabase = require('./describeDatabase'); -var expect = require('chai').expect; -var sworm = require('..'); +var describeDatabase = require('../describeDatabase'); +var sworm = require('../..') +var expect = require('chai').expect var database = { createTables: function(db, tables) { @@ -39,47 +39,47 @@ var database = { driverModuleName: "websql", - transactions: false + transactions: false, + + noModule: true }; var config = { driver: "websql", - config: { filename: __dirname + "/test.db" } + config: { + name: 'test' + } }; describeDatabase("websql", config, database, function () { describe('connection', function () { - it('can accept a file: URL', function () { - var db = sworm.db('file://' + config.config.filename + '?asdf=asdf'); + it('can connect with string for DB name', function () { + var db = sworm.db('test') return db.query('select * from people') - }); + }) - it('can accept a filename', function () { - var db = sworm.db(config.config.filename); + it('can connect with URL', function () { + var db = sworm.db('websql:///test') return db.query('select * from people') - }); + }) - context('openDatabase option', function () { - it('can provide a custom openDatabase implementation that doesnt work', function () { - var db = sworm.db({ - driver: 'websql', - config: {}, - openDatabase: function () { - throw new Error('openDatabase called') - }}) + it('can connect with openDatabase function', function () { + var called = false - expect(db.connect.bind(db)).to.throw('openDatabase called') + var db = sworm.db({ + driver: 'websql', + config: { + openDatabase: function() { + called = true + return window.openDatabase.apply(window, arguments) + }, + name: 'test' + } }) - it('can provide a working custom openDatabase implementation', function () { - var db = sworm.db({ - driver: 'websql', - config: config.config, - openDatabase: require('websql') - }) - - return db.query('select * from people') + return db.query('select * from people').then(function () { + expect(called).to.be.true }) }) - }); -}); + }) +}) diff --git a/test/describeDatabase.js b/test/describeDatabase.js index 39e46b7..1d802a3 100644 --- a/test/describeDatabase.js +++ b/test/describeDatabase.js @@ -10,23 +10,25 @@ require('es6-promise').polyfill(); module.exports = function(name, config, database, otherTests) { describe(name, function() { - describe("missing modules", function() { - var moduleName = __dirname + "/../node_modules/" + database.driverModuleName; + if (!database.noModule) { + describe("missing modules", function() { + var moduleName = __dirname + "/../node_modules/" + database.driverModuleName; - beforeEach(function() { - return fs.rename(moduleName, moduleName + ".missing"); - }); + beforeEach(function() { + return fs.rename(moduleName, moduleName + ".missing"); + }); - afterEach(function() { - return fs.rename(moduleName + ".missing", moduleName); - }); + afterEach(function() { + return fs.rename(moduleName + ".missing", moduleName); + }); - it("throws an exception if the driver module is not present", function() { - return expect(function() { - sworm.db(config).connect(); - }).to.throw("npm install " + database.driverModuleName); + it("throws an exception if the driver module is not present", function() { + return expect(function() { + sworm.db(config).connect(); + }).to.throw("npm install " + database.driverModuleName); + }); }); - }); + } context('with a database', function () { before(function () { diff --git a/websqlDriver.js b/websqlDriver.js index 0e075a9..d1dcb47 100644 --- a/websqlDriver.js +++ b/websqlDriver.js @@ -1,5 +1,3 @@ -var promisify = require('./promisify'); -var optionalRequire = require("./optionalRequire"); var debug = require('debug')('sworm:websql'); var paramRegex = require('./paramRegex') var urlUtils = require('url') @@ -26,7 +24,17 @@ module.exports = function() { self.connection.transaction(function(tx) { tx.executeSql(query, paramList, function(tx, result){ if (options.statement || options.insert) { - fulfil({id: result.insertId, changes: result.rowsAffected}); + var r = {} + + if (options.statement) { + r.changes = result.rowsAffected + } + + if (options.insert) { + r.id = result.insertId + } + + fulfil(r) } else { var results = [] for (var i = 0; i Date: Mon, 13 Mar 2017 15:26:37 +0100 Subject: [PATCH 6/7] websql: display setup for electron-mocha in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index cff8ae2..2c7e40f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,4 @@ services: - mysql before_script: - mysql -e 'create database sworm;' + - export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start From 5202d2dbe21b9e5dd9f259a66a417e9523d53a52 Mon Sep 17 00:00:00 2001 From: Tim Macfarlane Date: Mon, 13 Mar 2017 15:37:20 +0100 Subject: [PATCH 7/7] websql: docs --- readme.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0677da5..14e831e 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,7 @@ A very lightweight **write only** Node.js ORM, with support for: * MySQL * Oracle DB * Sqlite 3 +* Browser Web SQL ## NPM @@ -20,6 +21,8 @@ Then install a database driver, one of: npm install oracledb npm install sqlite3 +There's no need to install a driver for Web SQL, sworm will pick it up from the `window` object. + See [sworm](https://www.npmjs.org/package/sworm) in NPM. ## Write Only? @@ -158,7 +161,7 @@ sworm.db(url) * `url`, see urls for databases in respective section below - * `options.driver`, one of `'mssql'`, `'mysql'`, `'pg'`, `'oracle'` or `'sqlite'`. + * `options.driver`, one of `'mssql'`, `'mysql'`, `'pg'`, `'oracle'`, `'sqlite'` or `'websql'`. * `options.config` see configuration for databases in respective section below * `url` a connection URL, the following are supported @@ -301,6 +304,25 @@ sworm.db(url) } ``` +* **websql** + + URL: `websql:///db-name` or `db-name` + + ```js + { + driver: 'websql', + config: { + name: 'db-name', + + // the `openDatabase` function to connect to the DB, defaulting to `window.openDatabase` + openDatabase: window.openDatabase, + + // dababase size, defaulting to 5M + size: 5 * 1024 * 1024 + } + } + ``` + ### Close Close the connection after use: @@ -326,6 +348,7 @@ There are various schemes you can use: * `sworm:pg` exact query passed to postgres * `sworm:oracle` exact query passed to oracle * `sworm:sqlite` exact query passed to sqlite3 +* `sworm:websql` exact query passed to websql ## Models