Giter Club home page Giter Club logo

Comments (7)

kornelski avatar kornelski commented on June 12, 2024 3

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.

kornelski avatar kornelski commented on June 12, 2024 1

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.

TheNeikos avatar TheNeikos commented on June 12, 2024

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.

neithernut avatar neithernut commented on June 12, 2024

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.

neithernut avatar neithernut commented on June 12, 2024

Yep, but it still yields an error if the file could not be opened.

from rustbreak.

Boscop avatar Boscop commented on June 12, 2024

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.

TheNeikos avatar TheNeikos commented on June 12, 2024

This discussion should be fixed once #67 (comment) is implemented. I think further discussion should happen there!

from rustbreak.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.