-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
add the ability to have some "undroppable" initial data #85
Comments
Hey, @cloud-walker. Please note that If you wish to reset the state, consider combining drop with your seeding function: import { drop } from '@mswjs/data'
function seed(db) {
db.user.create({...})
db.todo.create({...})
}
function resetDb(db) {
drop(db)
seed(db)
} Would this approach work for your use case? |
We've also discussed the reset API here, where the following API was suggested: import { factory, snapshot } from '@mswjs/data'
const db = factory({...})
// seed your db...
db.user.create(...)
// Take the snapshot of database entities
// in this point of time.
const reset = snapshot(db)
// change the entities...
db.user.update(...)
db.todo.create(...)
// Reset to the exact state when
// the snapshot was taken.
reset() There's been no investigating whether such API is possible with the current architecture, but if we ever adopt a reset API, it'd look similar to this. |
Thats how I solved the issue with my current BTW the snapshot proposal could solve the use case! |
Closing this in favor of #86. |
In my current custom fake data implementation, I have the ability to seed the database with some initial data, that will remain untouched across drops:
Currently using
@mswjs/data
, if I reset the db withdrop(db)
, I lose ALL the data, and I think is not practical to reseed the data on each test 🤔The text was updated successfully, but these errors were encountered: