Skip to content

Commit

Permalink
don't map to promise
Browse files Browse the repository at this point in the history
  • Loading branch information
Megapixel99 committed Jan 19, 2024
1 parent d67e604 commit 8634a41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
25 changes: 11 additions & 14 deletions lib/dialects/sqlanywhere/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,19 @@ class Client_Sqlanywhere extends Client {

// Runs the query on the specified connection, providing the bindings
// and any other necessary prep work.
_query(connection, obj) {
async _query(connection, obj) {
if (!obj.sql) throw new Error('The query is empty');

return new Promise((resolve, reject) => {
let cb = (err, response) => {
if (err) return reject(err);
obj.response = response;
resolve(obj);
};
if (obj.bindings) {
return connection.exec(obj.sql, obj.bindings, cb);
}
return connection.exec(obj.sql, cb);
});
if (obj.bindings) {
obj.response = connection.exec(obj.sql, obj.bindings);
}
obj.response = connection.exec(obj.sql);
return obj;
}

// Process the response as returned from the query.
processResponse(obj, runner) {
let response = obj.response;
const method = obj.method;
const method = obj.method;
if (obj.output) return obj.output.call(runner, response);
switch (method) {
case 'select':
Expand All @@ -163,6 +156,10 @@ class Client_Sqlanywhere extends Client {
}
}

postProcessResponse(processedResponse, queryContext) {
return processedResponse;
}

ping(resource, callback) {
resource.exec('SELECT 1', [], callback);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/execution/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ class Runner {
// dropColumn()/renameColumn(), it will be a Promise for the transaction
// containing the complete rename procedure.
return queryPromise
.then((resp) => this.client.processResponse(resp, runner))
.then((resp) => {
return this.client.processResponse(resp, runner);
})
.then((processedResponse) => {
const postProcessedResponse = this.client.postProcessResponse(
processedResponse,
Expand Down

2 comments on commit 8634a41

@Megapixel99
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With regard to the changes on these lines, I realized you could call the exec function without a callback after looking at the code snippet here, wrapping the callback in a promise is known to cause issues on older versions (sqlanywhere/node-sqlanywhere#32), but it was not apparent that newer versions also had this issue until I made this change.

The other changes just fix whitespace, define a method which seemed to be missing and... I forgot to revert my change on this line from when I had a debug logger...

@Megapixel99
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on this line was reverted by commit c33832c

Please sign in to comment.