-
Notifications
You must be signed in to change notification settings - Fork 60
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
feat: use transactions when writing to the database #527
Conversation
* @private | ||
*/ | ||
export function tap<T>(input: T): T { | ||
console.log(input); // eslint-disable-line no-console |
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.
Is this just for debugging?
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.
correct
…into feat-transactions
Current coverage is 90.03% (diff: 95.91%)@@ master #527 diff @@
==========================================
Files 170 176 +6
Lines 1849 1926 +77
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1644 1734 +90
+ Misses 205 192 -13
Partials 0 0
|
@@ -299,6 +298,10 @@ export default async function initializeClass<T: Class<Model>>({ | |||
...belongsTo | |||
}); | |||
|
|||
if (!hooks) { |
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.
Just wondering if this could be embedded into L132?
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.
This takes care of edge cases where hooks
is null
, 0
, false
or any other falsy value besides undefined
. Those edge cases should never occur but this accounts for them just in case.
Destructed defaults only work if the value is undefined
.
set(subject, 'image', image); | ||
}); | ||
|
||
afterEach(teardown); | ||
|
||
it('can add a record to the relationship', async () => { | ||
console.log(image.changeSets); |
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.
There's another log here, just fyi.
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.
Nice find!
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.
Everything else looks good to me
This PR introduces a public transaction api to the model class. Changes are backwards
compatible with the previous model api.
Internally, all methods that modify the state of the database are wrapped in transactions.
If the transaction fails, all calls to
create
,save
, orupdate
will be rolled back tothe state before the transaction began.
Example:
Working With Transactions
You have the ability to manually specify the transaction that will be used for a
create
,update
, orsave
call with the static and instance method,transacting
.Example:
You can also manually trigger create a transaction if you plan on creating many
model instances as once.
Example: