Lazy vtable loading for DatabaseInMemory

Also fixed a few deserialization bugs, because (obviously)
it wasn't well tested.