brianc / node-sql

SQL generation for node.js
MIT License
1.05k stars 191 forks source link

Don't export instance #366

Open lukechilds opened 7 years ago

lukechilds commented 7 years ago

Resolves https://github.com/brianc/node-sql/issues/365

Made the change mentioned in #365. Also fixed tests to work with new syntax.

spion commented 7 years ago

While its a good idea, this is also likely to break a lot of apps using node-sql

lukechilds commented 7 years ago

@spion Yep, would definitely have to be SemVer major.

Should just be a search and replace to update though:

const sql = require('sql');

to:

const Sql = require('sql');
const sql = new Sql();

Which is probably what most developers intended to implement.

lukechilds commented 7 years ago

Or to make upgrading super easy we could wrap the export in a function:

module.exports = new Sql(DEFAULT_DIALECT, {});

would become

module.exports = () => new Sql(DEFAULT_DIALECT, {});

And then you could literally do a search/replace to upgrade:

require('sql') -> require('sql')()

But personally I'd go with the first option.