Skip to content

Commit

Permalink
Merge pull request #36
Browse files Browse the repository at this point in the history
Add conditional imports and fiddle with protocol method types
  • Loading branch information
Bilbottom authored Sep 10, 2023
2 parents 8e61fd6 + 630a3a4 commit 80406e2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,16 @@ To connect to a SQLite database in a read-only way, use the `uri=True` parameter
```python
db_conn = sqlite3.connect("file:path/to/database.db?mode=ro", uri=True)
```

## Contributing 🤝

The Python packaging is managed with [Poetry](https://python-poetry.org/) (check which version in the [poetry.lock](poetry.lock) file), but that should be the only dependency.

To get started, just clone the repo, install the dependencies, and enable [pre-commit](https://pre-commit.com/):

```bash
poetry install --sync --with dev,test
pre-commit install --install-hooks
```

Happy coding! 🎉
13 changes: 10 additions & 3 deletions db_query_profiler/query_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
import functools
import inspect
import pathlib
import sys
import timeit
import warnings
from typing import Any, Callable, Generator, List, Union

import tqdm
from typing_extensions import Protocol

if sys.version_info[:3] >= (3, 8, 0):
from typing import Protocol
else:
from typing_extensions import Protocol


class DatabaseConnection(Protocol):
"""
Database connector to run SQL against the database.
"""

def execute(self, *args, **kwargs) -> Any:
def execute(self, *args: Any, **kwargs: Any) -> Any:
"""
Execute a statement.
"""
Expand Down Expand Up @@ -142,7 +147,9 @@ def _create_query_runners(
Runner(
# runner=lambda: db_conn.execute(file.read_text()), # lambda is only keeping the last query for each runner
runner=functools.partial(
_execute_query, query=file.read_text(), db_conn=db_conn
_execute_query,
query=file.read_text(),
db_conn=db_conn,
),
name=file.name,
)
Expand Down
28 changes: 19 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages = [{include = "db_query_profiler"}]
[tool.poetry.dependencies]
python = "^3.7"
tqdm = "^4"
typing-extensions = "^4"
typing-extensions = { version = "^4", python = "<3.8" }

[tool.poetry.group.dev]
optional = true
Expand Down

0 comments on commit 80406e2

Please sign in to comment.