Files
chia-blockchain/chia/_tests/util/db_connection.py
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Earle Lowe
452cbf890d build(deps): bump ruff from 0.14.6 to 0.14.13 (#20439)
* build(deps): bump ruff from 0.14.6 to 0.14.13

Bumps [ruff](https://github.com/astral-sh/ruff) from 0.14.6 to 0.14.13.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](https://github.com/astral-sh/ruff/compare/0.14.6...0.14.13)

---
updated-dependencies:
- dependency-name: ruff
  dependency-version: 0.14.13
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* ruff fixes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Earle Lowe <e.lowe@chia.net>
2026-02-10 11:01:17 -08:00

37 lines
1.0 KiB
Python

from __future__ import annotations
import tempfile
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from pathlib import Path
import aiosqlite
from chia.util.db_wrapper import DBWrapper2, generate_in_memory_db_uri
@asynccontextmanager
async def DBConnection(
db_version: int,
foreign_keys: bool | None = None,
row_factory: type[aiosqlite.Row] | None = None,
) -> AsyncIterator[DBWrapper2]:
db_uri = generate_in_memory_db_uri()
async with DBWrapper2.managed(
database=db_uri,
uri=True,
reader_count=4,
db_version=db_version,
foreign_keys=foreign_keys,
row_factory=row_factory,
) as db_wrapper:
yield db_wrapper
@asynccontextmanager
async def PathDBConnection(db_version: int) -> AsyncIterator[DBWrapper2]:
with tempfile.TemporaryDirectory() as directory:
db_path = Path(directory).joinpath("db.sqlite")
async with DBWrapper2.managed(database=db_path, reader_count=4, db_version=db_version) as db_wrapper:
yield db_wrapper