mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-20 16:08:51 +03:00
5b39550f73
* convert datalayer to DBWrapper2 (all write) * more read, less write * remove unneeded connection managers * and... close it * data store now creates its own wrapper * Drop unused hint DataLayer.batch_update_db_wrapper * require named arguments for most of `DBWrapper2.create()`
21 lines
654 B
Python
21 lines
654 B
Python
from pathlib import Path
|
|
from chia.util.db_wrapper import DBWrapper2
|
|
import tempfile
|
|
|
|
|
|
class DBConnection:
|
|
def __init__(self, db_version: int) -> None:
|
|
self.db_version = db_version
|
|
|
|
async def __aenter__(self) -> DBWrapper2:
|
|
self.db_path = Path(tempfile.NamedTemporaryFile().name)
|
|
if self.db_path.exists():
|
|
self.db_path.unlink()
|
|
self._db_wrapper = await DBWrapper2.create(database=self.db_path, reader_count=4, db_version=self.db_version)
|
|
|
|
return self._db_wrapper
|
|
|
|
async def __aexit__(self, exc_t, exc_v, exc_tb) -> None:
|
|
await self._db_wrapper.close()
|
|
self.db_path.unlink()
|