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

Persistent database acts like In-Memory database #6

Closed
ciscorucinski opened this issue May 15, 2018 · 3 comments
Closed

Persistent database acts like In-Memory database #6

ciscorucinski opened this issue May 15, 2018 · 3 comments

Comments

@ciscorucinski
Copy link

Summary

It appears that the persistence of the data in a database file is not persistent at all, but all in-memory.

Background

I have created a new Store object with a filename parameter. The database file is created. The code uses a custom class that extends minidb.Model. The data is held in the custom Model class that I created and I can call .save(...) and .load(...) with the correct results outputted to me.

However, when I try to view the data in the database in a 3rd party app. Nothing shows up in the db table!

I tried to only .save(...) the results to the databases in one run-session, and then .load(...) the persisted data in another run-session. However, no data was loaded in my program at all.

Code

This code works and displays the contents of the "database" to the console; however, nothing appears in the database file.

class AndroidStudioRelease(minidb.Model):
    date = str
    name = str
    category = str
    release_type = str
    filename = str
    location = str
    sha256 = str
    filetype = str
    platform = str

...

db = minidb.Store('android-studio-downloads')
db.register(AndroidStudioRelease)

...

release = AndroidStudioRelease(date=date, name=name, category=category, release_type=release_type, filename=filename, location=download_location, sha256=sha256, filetype=filetype, platform=platform)
release.save(db)

...

for release in AndroidStudioRelease.load(db, (AndroidStudioRelease.c.platform == "Linux") & (AndroidStudioRelease.c.category == "Preview")):
    print(release)
@thp
Copy link
Owner

thp commented May 15, 2018

Did you call commit and/or close?

@ciscorucinski
Copy link
Author

Thank you for the quick reply. I was going off of the documentation from the git README file. That didn't state anything about committing or closing. I ended up calling db.close() at the very end and now I can see my data persist in the database!!

It appears even example.py doesn't use commit or close, and I didn't find anything in the documentation about needing those two methods. Did I miss it somewhere?

@thp
Copy link
Owner

thp commented May 17, 2018

Good point. Mostly that's because the example by default uses an in-memory database, so no persistence is necessary. I've added a paragraph describing db.close() and db.commit() to the part where the example talks about saving to a file.

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