Open leocasarsa opened 8 years ago
echo .backup foo-42.bdb | sqlite3 ./foo.bdb
Also, if you want to do something hypothetically, without permanently modifying the database, you can do it inside a transaction:
bdb.execute('BEGIN')
# Mess around -- interactively, if you like.
bdb.execute('...')
# File will not be modified until:
bdb.execute('COMMIT')
Or a savepoint, which is nicer for the Python API and nests, unlike transactions:
with bdb.savepoint():
bdb.execute('...')
# not saved yet
print 'ok'
# saved once you see 'ok'
If you don't like your hypothetical changes, you can roll back out of a transaction, or raise an exception to abort a savepoint:
bdb.execute('BEGIN')
...
bdb.execute('ROLLBACK')
try:
with bdb.savepoint():
...
if not ok:
raise NotOKException
except NotOKException:
pass
Nice! We should either make this more visible or make it standard to be inside a transaction.
http://probcomp.csail.mit.edu/bayesdb/doc/bql.html#transactions http://probcomp.csail.mit.edu/bayesdb/doc/api.html#bayeslite.BayesDB.savepoint
The docstring for BayesDB.savepoint() is a little terse. I will expand with a short example.
The autosave system of bdb files makes it hard to track in which state the bdb file currently is.
Granted, one could do this by initializing a population and calling
pop.analysis_status()
, for instance, but this is not quick to do if someone works on multiple bdb files. Being able to copy and rename the bdb file after making the population - or maybe after each crucial inference step to avoid losing previous costly inference steps- would come in handy.