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 a way to persist data to a file #1
Comments
I could work on this but am not sure how you expect it. There could be a new export import { db, register, enablePersistence } from "@tducasse/js-db";
enablePersistence(process.cwd() + '/database.json')
register("users");
db.users.insert({ name: "John" });
const user = db.users.findOne({ name: "John" });
console.log(user); |
Hey, this sounds good! Happy to go with this if you want to have a try! The way I initially thought about this was two functions, one to save to a file, one to restore from a file, and maybe call the save to file function either manually or automatically (on each update) if persistence is enabled, and the restore function when the app starts. |
That sound also good. This could be This would work fine in browsers but the problem I see with that is that somehow the path should be specified if |
Or you could specify through a config file or something, and it's picked up automatically at the start.
And then in db.persist
Now I'm guessing we could have a check at the start of the app, maybe it even tries to create the file, and if it doesn't work or the filepath is not configured, then it just prints a warning and disables the persistence. What do you think? Sorry for the formatting I'm on a phone right now! |
That sound imho great. If it's ok for you I could start with the implementation. |
Yes, feel free to handle it however you want to be honest, and if you push a PR, we can review it together, and maybe I'll work on the config file later on 🙂 Happy to help if you have issues along the way, and thanks for the help! |
Currently, the data is reset every time we relaunch the application.
Add a way to save the data to a json file, and restore it from the file later on.
The text was updated successfully, but these errors were encountered: