Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Fix query function for sqlserver client (#119)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin authored Oct 20, 2020
1 parent 2da27e6 commit a879e83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,20 @@ describe('db', () => {
}, 5000);
});
});

it('should query single result from function', async () => {
const query = dbConn.query('SELECT CURRENT_TIMESTAMP');
const result = await query.execute();
expect(result[0].rows[0]).to.be.not.null;
expect(result[0].rowCount).to.eql(1);
let expected;
if (dbClient === 'sqlserver') {
expected = 1;
} else if (dbClient === 'sqlite') {
expected = 0;
}
expect(result[0].affectedRows).to.eql(expected);
});
}

describe('.executeQuery', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/db/clients/sqlserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export function query(conn, queryText) {
queryRequest = request;

const result = await promiseQuery;
const data = request.multiple ? result.datasets : result.dataset;
const affectedRows = result.affectedRows.reduce((a, b) => a + b, 0);
const data = request.multiple ? result.recordsets : result.recordset;
const affectedRows = result.rowsAffected ?
result.rowsAffected.reduce((a, b) => a + b, 0) :
undefined;

const commands = identifyCommands(queryText).map((item) => item.type);

Expand Down

0 comments on commit a879e83

Please sign in to comment.