Comments (7)
Ahm, indeed. In such case I still think it'd be better to have explicit data loss if you choose so, e.g.
let db = Db::from_file("path").unwrap_or_else(|| Db::blank());
from rustbreak.
Note that sqlite (in its typical usage) does not fail. It always succeeds - if the file doesn't exist, it's created. If it exists, it's loaded.
from rustbreak.
It's a fair question, the reason why I've structured it this way is to let you decide what happens.
So far in my applications I have simply tried loading, and ignored if it fails. This means it could fail for a lot of different reasons, but it's the easiest way for small applications.
If you want to be more involved, you can look at the return status and check the error kind, if it was a backend error (Any form of IO Error) or perhaps a Deserialization error? (As seen here, where no bytes are fed into it)
If it is a Deserialization Error the cause is then specific to the library you are using. This allows you to drill down into what exactly went wrong and do the right thing for your specific application.
Regarding having it behave like SQLite, I'd love that behaviour, but I want Rustbreak to be usable from a lazy_static!
macro. If a create
of any form could fail because of non-existent databases or other issues that are not unrecoverable then it would complicate this heavily. I am happy to discuss this though!
from rustbreak.
Silently overriding an existing file, discarding its contents, does not sound like a good idea to me. It certainly breaks user expectation.
Maybe a differentiation via different functions would be appropriate. E.g. a new function FileDatabase::load_from_path()
would behave like SQLite, erroring out if an existing file could not be opened and FileDatabase::from_path()
would be flagged with a warning in the documentation. Or you could specify the behavior explicitly using some enum.
from rustbreak.
Yep, but it still yields an error if the file could not be opened.
from rustbreak.
I think it would be nice to get sqlite-like behavior, and so that the function that opens the db file also takes a closure that will return the initial data to use if the db file doesn't exist (and will only be called in that case).
from rustbreak.
This discussion should be fixed once #67 (comment) is implemented. I think further discussion should happen there!
from rustbreak.
Related Issues (20)
- Missing detailed information from the back-end HOT 2
- Errors with newest stable Rust HOT 5
- Problems with Ron and json Value integers HOT 6
- Load performance problems HOT 15
- [FR] we should be able to minify the output HOT 6
- Bincode not loading in v2 rc3 HOT 14
- Database::try_read() HOT 2
- FileBackend::from_file / Database::from_file docs missing: Does it load()? HOT 2
- Loading database with empty File fails HOT 18
- Update RON HOT 1
- Transition to Rust edition 2018
- Use `data.read()` instead of `data.write()` in `save()` HOT 1
- Describing generic database HOT 6
- Run `cargo fmt` HOT 1
- More checks in CI HOT 3
- UB with yaml DeSer HOT 5
- RUSTSEC-2020-0077: memmap is unmaintained
- Out of memory if file size > memory size HOT 1
- support speedy https://docs.rs/speedy/ HOT 1
- wasm support + wasi support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rustbreak.