-
-
Notifications
You must be signed in to change notification settings - Fork 53
feat: adds configurable persistBy option
#119
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
Conversation
|
Drafting this PR pending documentation. @kiaking your input would be most appreciated. |
Codecov Report
@@ Coverage Diff @@
## dev #119 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 80 91 +11
Branches 11 13 +2
=========================================
+ Hits 80 91 +11
Continue to review full report at Codecov.
|
|
Thank you so much for this! I think it's looking good. Could we have |
|
Ah yea, forgot to mention, if We could call the method explicitly: // invoker
this.entities = await this.persist(method, { data })
// invokee
persist(method: PersistOption, payload: any): Promise<Collections> {
switch (method) {
case 'create':
return this.model.create(payload)
case 'insert':
return this.model.insert(payload)
case 'update':
return this.model.update(payload)
case 'insertOrUpdate':
return this.model.insertOrUpdate(payload)
}
}What do you think @kiaking? In the meantime I’ll start adding to docs. |
Yeah maybe that would be better, since |
save optionpersistBy option
|
The original idea of configuring the For example, if a user chooses to defer persistence by setting For that reason alone, reverting back to the original idea of configuring Users can now defer persistence and const response = await User.api().get('...', { save: false, persistBy: 'create' })
// do something
await response.save() |
persistBy optionpersistBy option
kiaking
left a comment
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.
Ah good point! Nice idea. I like the persistBy option 👍
Resolves #93
Type of PR:
Breaking changes:
Details
This PR adds a new optional
persistBy?: stringoption to allow configuring a preferred method of persistence. The default value is'insertOrUpdate'.In a nutshell, while this issue comment explains the idea pretty well, the plugin option
persistBycan be configured to override the default persistence behaviour.The signature for this options is:
'create' | 'insert' | 'update' | 'insertOrUpdate'Beyond that, the plugin will warn users of any invalid value configured and fallback to the default
insertOrUpdatemethod.