Skip to content

fix: Move iConn compatibility code to iConn itself #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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