Skip to content

Commit

Permalink
fix: Move iConn compatibility code to iConn itself (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
kadler committed Apr 1, 2020
1 parent 9f12b97 commit 73d798d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
26 changes: 3 additions & 23 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,15 @@ class Connection {
/**
* @description Creates a new Connection object
* @constructor
* @param {object | string} optionsOrDb
* @param {string} user
* @param {string} pwd
* @param {object} [restConfig]
* @param {object} options
*/
constructor(optionsOrDb, username, password, restOptions) {
constructor(options) {
this.commandList = [];
this.returnError = true;
this.verbose = false;
let options = optionsOrDb;

// maintain compatibility with versions < 1.0
if (typeof options !== 'object') {
options = {
returnError: false,
transport: 'idb',
transportOptions: {
database: optionsOrDb,
username,
password,
},
};
if (restOptions && typeof restOptions === 'object') {
if (restOptions.host) {
// pre v1.0 falls back to idb transport when host is not specified
options.transport = 'rest';
}
options.transportOptions = { ...options.transportOptions, ...restOptions };
}
throw new Error('options must be an object');
}

this.transport = options.transport;
Expand Down
31 changes: 30 additions & 1 deletion lib/Deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,37 @@ class iSql {

// DEPRECATED: For now, routes call to Connection, but will be removed at a later time.
class iConn {
/**
* @description Creates a new iConn object
* @constructor
* @param {string} db
* @param {string} user
* @param {string} pwd
* @param {object} [option]
*/
constructor(db, user, pwd, option) {
this.connection = new Connection(db, user, pwd, option);
iConnDeprecate('As of v1.0, class \'iConn\' is deprecated. Please use \'Connection\' instead.');

// Assume using idb as the transport
const options = {
returnError: false,
transport: 'idb',
transportOptions: {
database: db,
username: user,
password: pwd,
},
};

if (option && typeof option === 'object') {
// pre v1.0 falls back to idb transport when host is not specified
if (option.host) {
options.transport = 'rest';
}
options.transportOptions = { ...options.transportOptions, ...option };
}

this.connection = new Connection(options);
}

/**
Expand Down

0 comments on commit 73d798d

Please sign in to comment.