-
Notifications
You must be signed in to change notification settings - Fork 96
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
Added hooks to support mongo-db transaction #276
Added hooks to support mongo-db transaction #276
Conversation
This looks really interesting, thank you! For new features like that we do need some tests though. A good start would be to show how the example would work and then go from there. |
I think that the
This would allow the hook to be used on a per service basis, instead of specifying at Great work! |
68e0525
to
2334ae2
Compare
Thanks for reviewing. I've modified the |
3dd2ea9
to
272133d
Compare
Hi. I've added test cases as working-sample and updated README.md for prerequisite. Please review for additional changes to be added. |
272133d
to
acda7bf
Compare
Hi @daffl, |
This is really tricky in Travis CI. Looks like the best shot is the run-rs package. If it works this would also allow local testing without needing a MongoDB server running. |
Thanks daffl 👍 I will also try to figure a way out . |
c368e33
to
fe3ba71
Compare
Hi @daffl , Awaiting your suggestion/review. |
fe3ba71
to
50b8fab
Compare
fa35a18
to
02d80da
Compare
Dropping supported Node versions would be a breaking change which planned for the next major release. We'd either have to wait merging this until then or have a promise based version for now. |
Hi @daffl |
Sounds good, thanks! |
Mind you, I am planning to make a major release with some other updates in the next couple of weeks that would drop Node 6 and use |
Ok, I just merged the updates I mentioned. If you merge your changes with that version we can get it released 😄 |
Sure @daffl 👍 |
dd85090
to
2685be7
Compare
@daffl awaiting your review 👍 |
lib/service.js
Outdated
return result.map(item => (item.toObject ? item.toObject() : item)); | ||
if (params.mongoose && params.mongoose.session && typeof data === 'object') { | ||
const createOptions = Object.assign({}, params.mongoose); | ||
return model.create([data], createOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even when you are in a session you could still create array data right? Why not just pass createOptions
into the model.create(data)
that we already have in https://github.com/feathersjs-ecosystem/feathers-mongoose/pull/276/files#diff-6ce8873d3951d1d3483af360fa1f4a93R155
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @daffl ... I've passed it as a option to create model...
Note: When a user try creating a single record 'service.create(obj, mongooseOptions)' we need to internally convert it into 'service.create([obj], mongooseOptions)' and them return result[0] because the 'mongoose' dependency does not accept options for a single object creation as it supports a spread of object.
2685be7
to
d645702
Compare
- added test case sample
- tests modified for transactions
d645702
to
2acd002
Compare
Sweet, made some minor tweaks and released as v7.1.0, thank you! |
Summary
To directly add api-request level hooks and service level hooks to implement mongo-db-transaction
Other Information
The create and remove methods of service.js were modified to pass the params.mongoose to the mongoose dependency to carry the database session and to commit or rollback at the end of api-request or the service call.
Note: This is left optional to ensure the codes already written without this param still works fine.