This throws a ValueError: I/O operation on closed file.:
db = TinyDB('./db.json').table('foo')
db.insert({'something': 'else'})
db.insert({'int': 13})
print(db.search(Query()['int'] == 13))
print(db.all())
while this works:
db = TinyDB('./db.json')
table = db.table('foo')
table.insert({'something': 'else'})
table.insert({'int': 13})
print(table.search(Query()['int'] == 13))
print(table.all())
It took me and @alexghr a couple of hours to figure out it had to do with the garbage collector deleting the db object (and thus closing the database).
Would it make sense to have the documentation explicitly state that losing the reference to the database will mess up your tables?