-
Notifications
You must be signed in to change notification settings - Fork 2
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
Promise api #58
Comments
I think using a Promise library like bluebird will help out a lot in cases like this. Using a promisify function like: https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyallobject-target--object-options---object will likely be best if we want to support both a node callback style api and a promise-based one. Otherwise, the code can get convoluted in attempts to support both styles. At goodybag.com, we've successfully implemented promises on top of dirac.DAL API with no issues. |
Actually I considered using promisifyAll, but I don't like the added ugly "Async" suffix and the most important thing is that I can't 100% sure that it works for all functions. We don't even have any unit test for the auto generated promise api. Of course, you as the author are familiar with the whole code base and may have the confidence, but for anyone else it's a different story. I am glad to know that you have used bluebird to implement promises api in production at goodybag.com with no issues, but I think providing the official support for promise api benefit new users a lot and can have unit tests to guard them. If possible, can we move forward to promise-based api and drop node callback style api before v1.0? For now, I will use "promiseifyAll" as you suggested. Thank you. |
With a Promise library, the caller = arguments.callee.caller.name; |
Hrmm... yeah, I always knew the @newlix if you can turn your code you posted into a PR, I can help out with amending the docs and adding some unit tests. The main thing I want to avoid while trying to support both callbacks and promises is situations where one is used over the other, but by some accident, both are invoked |
Also, sorry for the late reply! It's been busy at work |
I am currently porting the whole library and unit tests into promise-based. I found it might be easier to rewrite into promise-based first then using the Also, I think |
Yes, 1.0.0 will completely remove |
I have finished the porting. https://github.com/newlix/promise-dirac |
Also, I found some inconsistent parts between the code behavior and the document :
In the document:
but there is a check in the source code. if ( typeof this[ fnName ] != 'function' )
throw new Error('Dirac.DAL.before cannot find function `' + fnName + '`');
insert var query = {
type: 'insert'
, table: this.table
, values: values
, returning: ['*']
}; remove var query = {
type: 'delete'
, table: this.table
, where: typeof id == 'object' ? id : { id: id }
, returning: ['*']
}; update var query = {
type: 'update'
, table: this.table
, where: $query
, updates: $update
}; The examples in the document need update too. |
Hey, @newlix that's fantastic. Please please please circle back around and let me know what issues you end up happening with Promises (as it will inform the creation v1.0.0). I'll fix the docs. I believe I ended up writing the docs first and then implemented some of those features. Perhaps for one reason or another, I didn't get to implement the full spec :/ Thanks for letting know! |
Hi, I think we can both maintain our own unit tests, yours for node-style and mine for promise-based. Dirac V1.0.0 will have to pass all these tests if we want to support both node-style and promise-based. Please also close the resolved issues, I was wondering about some very old issues. Thanks a lot. |
Hi,
I found the promise api support is in the v1.0 proposal. I am using Koa , so the promise api is quite important for me. I try to promisify the dal.query and keep it backward compatible.
I turned this
into this
And the other functions which return
this.query($query,callback)
inherently return promise now and are backward compatible. Some functions likefindOne
andraw
need a little more works, but I think it won't be too hard.What do you think?
The text was updated successfully, but these errors were encountered: