Skip to content
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

Method to clean-up/delete db #4

Open
martinberoiz opened this issue Oct 28, 2020 · 3 comments
Open

Method to clean-up/delete db #4

martinberoiz opened this issue Oct 28, 2020 · 3 comments

Comments

@martinberoiz
Copy link
Member

Add a method that deletes self.dn and self.pn, or automatically delete when class is garbage collected?

@BrunoSanchez
Copy link
Contributor

Do you have a draft for such thing?

@BrunoSanchez
Copy link
Contributor

I think the main question is how to know when this is garbage collected? And besides, the user might in a certain case, keep the DB for later.

Probably we could work everything with tempfiles and offer a method to dump the database to a certain file for later storing.

from shutil import copyfile

...
def dump_db(self, filename='tinynpydb'):
    copyfile(self.dn, Path(filename).with_suffix(".dat"))
    copyfile(self.dp, Path(filename).with_suffix(".map"))

Also we could offer a flag to avoid cleaning the DB unintentionally. Leave it True as default

class NumPyDB(object):
    def __init__(self, database_name, mode="store", purgable=True):
        ...

@martinberoiz
Copy link
Member Author

The method called on destruction is called __del__.

So we could have something like:

class NumPyDB(object):
    def __init__(self, database_name, mode="store", purgeable=True):
        ...

    def __del__(self)
        if purgeable:
           # delete all pickles, clean up

Alternative to purgeable could be persist=False. But we should keep track somehow of the files we "own" (the ones tinynpdb creates) to delete only those when NumPyDB is gc'ed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants