From d76cbffa562f57872492a68714d04ff99d82e243 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Mon, 18 Jun 2018 21:36:02 +0200 Subject: [PATCH] Remove WebSQL dialect (#2647) * Add json support to the query builder for mysql refs #1036 Based on #1902 * Clarify supported version * Use native Buffer and Stream implementations * Remove WebSQL dialect --- CHANGELOG.md | 1 + README.md | 4 +- src/dialects/websql/index.js | 111 ----------------------------- src/dialects/websql/transaction.js | 48 ------------- src/index.js | 16 ++--- src/migrate/migrate-stub.js | 3 +- src/seed/seed-stub.js | 3 +- 7 files changed, 10 insertions(+), 176 deletions(-) delete mode 100644 src/dialects/websql/index.js delete mode 100644 src/dialects/websql/transaction.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dfe13f9fd..3ad1091edc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Drop support for Node.js 4 and 5 - `json` data type is no longer converted to `text` within a schema builder migration for MySQL databases (note that JSON data type is only supported for MySQL 5.7.8+) +- Removed WebSQL dialect #2461 # 0.14.6 - 12 Apr, 2018 diff --git a/README.md b/README.md index 5856eead84..03162084df 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ > **A SQL query builder that is _flexible_, _portable_, and _fun_ to use!** -A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle(including Oracle Wallet Authentication), WebSQL) query builder for +A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle(including Oracle Wallet Authentication)) query builder for Node.js and the Browser, featuring: - [transactions](http://knexjs.org/#Transactions) @@ -24,7 +24,7 @@ Node.js versions 6+ are supported. For support and questions, join the `#bookshelf` channel on freenode IRC -For an Object Relational Mapper, see: +For an Object Relational Mapper, see: - http://bookshelfjs.org - https://github.com/Vincit/objection.js diff --git a/src/dialects/websql/index.js b/src/dialects/websql/index.js deleted file mode 100644 index ee7acb4e9b..0000000000 --- a/src/dialects/websql/index.js +++ /dev/null @@ -1,111 +0,0 @@ -/* globals openDatabase:false */ - -// WebSQL -// ------- -import inherits from 'inherits'; - -import Transaction from './transaction'; -import Client_SQLite3 from '../sqlite3'; -import Promise from 'bluebird'; -import { assign, map, uniqueId, clone } from 'lodash' - -function Client_WebSQL(config) { - Client_SQLite3.call(this, config); - this.name = config.name || 'knex_database'; - this.version = config.version || '1.0'; - this.displayName = config.displayName || this.name; - this.estimatedSize = config.estimatedSize || 5 * 1024 * 1024; -} -inherits(Client_WebSQL, Client_SQLite3); - -assign(Client_WebSQL.prototype, { - - transaction() { - return new Transaction(this, ...arguments) - }, - - dialect: 'websql', - - // Get a raw connection from the database, returning a promise with the connection object. - acquireConnection() { - return new Promise((resolve, reject) => { - try { - /*jslint browser: true*/ - const db = openDatabase( - this.name, this.version, this.displayName, this.estimatedSize - ); - db.transaction(function(t) { - t.__knexUid = uniqueId('__knexUid'); - resolve(t); - }); - } catch (e) { - reject(e); - } - }); - }, - - // Used to explicitly close a connection, called internally by the pool - // when a connection times out or the pool is shutdown. - releaseConnection() { - return Promise.resolve() - }, - - // Runs the query on the specified connection, - // providing the bindings and any other necessary prep work. - _query(connection, obj) { - return new Promise((resolver, rejecter) => { - if (!connection) return rejecter(new Error('No connection provided.')); - connection.executeSql(obj.sql, obj.bindings, (trx, response) => { - obj.response = response; - return resolver(obj); - }, (trx, err) => { - rejecter(err); - }); - }); - }, - - _stream(connection, sql, stream) { - const client = this; - return new Promise(function(resolver, rejecter) { - stream.on('error', rejecter) - stream.on('end', resolver) - return client._query(connection, sql).then(obj => - client.processResponse(obj) - ).map(row => { - stream.write(row) - }).catch(err => { - stream.emit('error', err) - }).then(() => { - stream.end() - }) - }) - }, - - processResponse(obj, runner) { - const resp = obj.response; - if (obj.output) return obj.output.call(runner, resp); - switch (obj.method) { - case 'pluck': - case 'first': - case 'select': { - let results = []; - for (let i = 0, l = resp.rows.length; i < l; i++) { - results[i] = clone(resp.rows.item(i)); - } - if (obj.method === 'pluck') results = map(results, obj.pluck); - return obj.method === 'first' ? results[0] : results; - } - case 'insert': - return [resp.insertId]; - case 'delete': - case 'update': - case 'counter': - return resp.rowsAffected; - default: - return resp; - } - } - -}) - -export default Client_WebSQL; diff --git a/src/dialects/websql/transaction.js b/src/dialects/websql/transaction.js deleted file mode 100644 index 4cab74c868..0000000000 --- a/src/dialects/websql/transaction.js +++ /dev/null @@ -1,48 +0,0 @@ - -import makeKnex from '../../util/make-knex'; -import Promise from 'bluebird'; -import inherits from 'inherits'; -import { EventEmitter } from 'events'; - -function Transaction_WebSQL(client, container) { - client.logger.warn('WebSQL transactions will run queries, but do not commit or rollback') - const trx = this - this._promise = Promise.try(function() { - container(makeKnex(makeClient(trx, client))) - }) -} -inherits(Transaction_WebSQL, EventEmitter) - -function makeClient(trx, client) { - - const trxClient = Object.create(client.constructor.prototype) - trxClient.config = client.config - trxClient.connectionSettings = client.connectionSettings - trxClient.transacting = true - - trxClient.on('query', function(arg) { - trx.emit('query', arg) - client.emit('query', arg) - }) - trxClient.commit = function() {} - trxClient.rollback = function() {} - - return trxClient -} - -const promiseInterface = [ - 'then', 'bind', 'catch', 'finally', 'asCallback', - 'spread', 'map', 'reduce', 'tap', 'thenReturn', - 'return', 'yield', 'ensure', 'exec', 'reflect', - 'get', 'mapSeries', 'delay' -] - -// Creates a method which "coerces" to a promise, by calling a -// "then" method on the current `Target` -promiseInterface.forEach(function(method) { - Transaction_WebSQL.prototype[method] = function() { - return (this._promise = this._promise[method].apply(this._promise, arguments)) - } -}) - -export default Transaction_WebSQL diff --git a/src/index.js b/src/index.js index f4bd25d552..859c5a5601 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,7 @@ export default function Knex(config) { } else if (typeof config.client === 'function' && config.client.prototype instanceof Client) { Dialect = config.client } else { - const clientName = config.client || config.dialect + const clientName = config.client || config.dialect; Dialect = require(`./dialects/${aliases[clientName] || clientName}/index.js`) } if (typeof config.connection === 'string') { @@ -36,7 +36,7 @@ export default function Knex(config) { } // Expose Client on the main Knex namespace. -Knex.Client = Client +Knex.Client = Client; /* eslint no-console:0 */ @@ -46,7 +46,7 @@ Object.defineProperties(Knex, { console.warn( 'Knex.VERSION is deprecated, you can get the module version' + "by running require('knex/package').version" - ) + ); return '0.12.6' } }, @@ -56,17 +56,11 @@ Object.defineProperties(Knex, { return require('bluebird') } } -}) +}); // Run a "raw" query, though we can't do anything with it other than put // it in a query statement. Knex.raw = (sql, bindings) => { console.warn('global Knex.raw is deprecated, use knex.raw (chain off an initialized knex object)') return new Raw().set(sql, bindings) -} - -// Doing this ensures Browserify works. Still need to figure out -// the best way to do some of this. -if (process.browser) { - require('./dialects/websql/index.js') -} +}; diff --git a/src/migrate/migrate-stub.js b/src/migrate/migrate-stub.js index ef9800586c..1e0cbb3d9a 100644 --- a/src/migrate/migrate-stub.js +++ b/src/migrate/migrate-stub.js @@ -1,8 +1,7 @@ // Stub Migrate: // Used for now in browser builds, where filesystem access isn't -// available. Maybe we can eventually do websql migrations -// with jsonp and a json migration api. +// available. const StubMigrate = module.exports = function() {}; import Promise from 'bluebird'; diff --git a/src/seed/seed-stub.js b/src/seed/seed-stub.js index 9db3e68e11..a05eb4e338 100644 --- a/src/seed/seed-stub.js +++ b/src/seed/seed-stub.js @@ -1,8 +1,7 @@ // Stub Seed: // Used for now in browser builds, where filesystem access isn't -// available. Maybe we can eventually do websql migrations -// with jsonp and a json migration api. +// available. const StubSeed = module.exports = function() {}; import Promise from 'bluebird';