tedious-promises's People
tedious-promises's Issues
setPromiseLibrary throwing exception
I'm trying to switch to es6 promises but some reason setPromiseLibrary doesn't exist. Haven't checked the other version e.g. tp.sql().setPromiseLibrary.
tediousPromises.setPromiseLibrary('es6');
> TypeError: tediousPromises.setPromiseLibrary is not a function
After a bit of digging around I found out that this function isn't bound to the default instance in src/index.js. It works if this is added:
module.exports.setPromiseLibrary = defaultInstance.setPromiseLibrary.bind(defaultInstance);
I need it for one of my projects so I've forked it for now. Hope you can add in and publish to npm.
Cheers.
trouble to get the number of row count in a SELECT statements
I'm facing trouble to get the number of results row (my use case requires to have exactly one result per SQL command, otherwise it's an error). I made tedious promise working for everything except this rows count check. (I'm discovering promises ...)
promises.push(tp
.sql(command)
.execute()
.then(consolidate.bind(null, entities[property]))
.fail(function (error) {
client.trackException(new Error('Failure when querying database'),{ 'query' : command, 'details' : error.message});
console.log('failure with ' + command + '\n' + error.message);
}));
function consolidate(input, data) {
for (var property in data[0])
input[property] = data[0][property];
}
consolidate method is only called when there is one or more results, but not 0.
I've tried to switch the processing into then() body, but the javascript context wasn't the correct one (wrong entities[property] reference, the last one I assume (it's a loop)).
promises.push(tp
.sql(command)
.execute()
.then(function(results){
if(results.length == 1){
entities[property] = results[0]; // WRONG CONTEXT
}else{
// either 0 or > 1 isn't correct
console.log('lookup failure with ' + command);
}
})
.fail(function (error) {
client.trackException(new Error('Failure when querying database'),{ 'query' : command, 'details' : error.message});
console.log('failure with ' + command + '\n' + error.message);
}));
any hints/direction ?
regards
Support for stored procedures
Does the latest version of this library support calling stored procedure?
If yes, how to make a procedure call?
tedious promises doesn't listen to error event and can cause node to crash
events.js:141
throw er; // Unhandled 'error' event
^
ConnectionError: Login failed for user 'PoweredApp'.
at ConnectionError (/Users/c/BitBucket/powered-server/node_modules/tedious/lib/errors.js:21:12)
at Parser. (/Users/c/BitBucket/powered-server/node_modules/tedious/lib/connection.js:256:66)
at emitOne (events.js:77:13)
at Parser.emit (events.js:169:7)
at Parser. (/Users/c/BitBucket/powered-server/node_modules/tedious/lib/token/token-stream-parser.js:51:15)
at emitOne (events.js:77:13)
at Parser.emit (events.js:169:7)
at readableAddChunk (/Users/c/BitBucket/powered-server/node_modules/readable-stream/lib/_stream_readable.js:198:18)
at Parser.Readable.push (/Users/c/BitBucket/powered-server/node_modules/readable-stream/lib/_stream_readable.js:157:10)
at Parser.Transform.push (/Users/c/BitBucket/powered-server/node_modules/readable-stream/lib/_stream_transform.js:123:32)
Please support array of arrays as result option
Hi
Could you add an option that returns the result as an array of arrays?
So basically the result should be an array of rows, and each row is an array of columns.
result =
{
columns: ['col_1', 'col_2'],
rows:
[
[ 'row1_col1', 'row1_col2' ],
[ 'row2_col1', 'row2_col2' ]
]
};
The main reason is to reduce the amount of data I have to transfer to my client and repeating the column names over and over again is such a waste.
It also matches the CSV format much better which is often used with charts like D3.
Thanks
Bernd
connection object is null when failing to acquiring a connection from the pool
problem is on line 128
result from a procedure which has two select queries
I have a procedure which has two select statements.
The result of both select statements are returned into the result array.
For example, the first select statement produced 5 records and the second produced 3 records, the result array will have 8 records.
The question is, is there any easy way with which i can distinguish the results from two different select statements?
help with async await in tedious promises
hi guys. maybe my problem is not an issue related to tedious promises. but what approach do i take to implement async await ini this library. thanks for any insight.
TVP is not working
This code is not working (using tedious-promise)
return tp.sql("exec dbo.SPFilterUnsubscribedMails @TVP")
.parameter('TVP', TYPES.TVP, table)
.execute()
while this is working(using tedious)
return new Promise((resolve, reject) => {
var table = {
columns: [{
name: 'email', type: TYPES.NVarChar, length: 200
}],
rows: emails
}
var connection = new Connection(dbConfig);
connection.on('connect', function(err) {
if (err) {
console.log('error : '+err);
} else {
var r = new Request("SPFilterUnsubscribedMails", function (er, count) {
if (er) {
return reject(er);
connection.close();
}
if (count === 0) {
resolve([]);
connection.close();
}
});
r.addParameter('TVP', TYPES.TVP, table)
r.on('row', function(columns) {
resolve(columns.map(v => v.value));
connection.close();
});
connection.callProcedure(r);
}
});
})
I hope that I am clear. Let me know if you need any more info.
Add support for es6 promises
Add support for es6 promises without breaking existing use of Q promises.
Add Information about how to retrieve the inserted record
Something like this would be very helpful for those who wants that auto-generated ID on the callback from the request.
const query = INSERT INTO Address ( number ) VALUES('${number}'); select @@identity
;
tp.setConnectionConfig(config);
return tp.sql(query)
.execute()
.then(record => console.log('inserted', record))
.fail(error => res.status(400).send({ message: error }));
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.