diff --git a/.github/workflows/aiosql-package.yml b/.github/workflows/aiosql-package.yml index cb6f8c38..26e5557f 100644 --- a/.github/workflows/aiosql-package.yml +++ b/.github/workflows/aiosql-package.yml @@ -17,6 +17,7 @@ jobs: matrix: # https://github.com/actions/python-versions (versions-manifest.json) # https://downloads.python.org/pypy/versions.json + # 3.14 KO on pydantic build dependences 2024-10-27 python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.10"] steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 80ba68d2..678034d6 100644 --- a/Makefile +++ b/Makefile @@ -22,12 +22,11 @@ WAIT = ./tests/wait.py help: @echo "useful targets:" echo " - help: show this help" - echo " - venv: generate python virtual environment directory" - echo " - venv.dev: make venv suitable for development" + echo " - dev: make environment suitable for development" echo " - venv.prod: make venv suitable for production" echo " - venv.last: fill venv with latests packages" echo " - clean: clean up various generated files and directories" - echo " - clean.venv: also remove the venv directory" + echo " - clean.dev: also remove the development environment" echo " - check.pytest: run pytest tests" echo " - check.mypy: run mypy type checker" echo " - check.flake8: run flake8 code style checks" @@ -47,27 +46,33 @@ help: # so the result is kind of a mess, so we attempt at doing nearly nothing and # hope for the best, i.e. dependencies will not break the library. # -.PHONY: venv.dev venv.prod venv.last venv: $(PYTHON) -m venv venv source venv/bin/activate $(PIP) install --upgrade pip -venv.dev: venv +venv/.dev: venv source venv/bin/activate $(PIP) install .[dev,dev-postgres,dev-sqlite,dev-duckdb] + touch $@ -venv.dist: venv +venv/.dist: venv source venv/bin/activate $(PIP) install .[dist] + touch $@ +.PHONY: venv.prod venv.prod: venv +.PHONY: venv.last venv.last: venv source venv/bin/activate $(PIP) install $$($(PIP) freeze | cut -d= -f1 | grep -v -- '^-e') -U +.PHONY: dev +dev: venv/.dev + # direct module installation for github or docker ifdef VENV PIP = $(VENV)/bin/pip @@ -94,6 +99,9 @@ clean: clean.venv: clean $(RM) -r venv $(MODULE).egg-info +.PHONY: clean.dev +clean.dev: clean.venv + .PHONY: clean.docker clean.docker: clean docker.rm $(MAKE) -C docker clean diff --git a/aiosql/queries.py b/aiosql/queries.py index f39b1b73..3106a442 100644 --- a/aiosql/queries.py +++ b/aiosql/queries.py @@ -1,3 +1,4 @@ +import re import inspect from pathlib import Path from types import MethodType @@ -6,7 +7,7 @@ from typing import Any, Callable, List, Optional, Set, Tuple, Union, Dict, cast from .types import DriverAdapterProtocol, QueryDatum, QueryDataTree, QueryFn, SQLOperationType -from .utils import SQLLoadException +from .utils import SQLLoadException, log class Queries: @@ -72,6 +73,10 @@ def _params( else: return args + def _look_like_a_select(self, sql: str) -> bool: + # skipped: VALUES, SHOW + return re.search(r"(?i)\b(SELECT|RETURNING|TABLE|EXECUTE)\b", sql) is not None + def _query_fn( self, fn: Callable[..., Any], @@ -93,6 +98,9 @@ def _query_fn( qfn.sql = sql qfn.operation = operation qfn.attributes = attributes + # sanity check in passing… + if operation == SQLOperationType.SELECT and not self._look_like_a_select(sql): + log.warning(f"query {fname} may not be a select, consider adding an operator, eg '!'") return qfn # NOTE about coverage: because __code__ is set to reflect the actual SQL file diff --git a/docs/source/index.rst b/docs/source/index.rst index 90b2d9ed..680c546c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -213,8 +213,8 @@ using ``aiosqlite`` and ``asyncio``: It may seem inconvenient to provide a connection on each call. You may have a look at the `AnoDB `__ `DB` class which wraps both a database connection *and* queries in one -connection-like extended object, including managing a pool and performing -automatic reconnection if needed. +connection-like extended object, including performing automatic reconnection +when needed. Why you might want to use this ------------------------------ diff --git a/docs/source/versions.rst b/docs/source/versions.rst index 3c0d34e2..2765a2db 100644 --- a/docs/source/versions.rst +++ b/docs/source/versions.rst @@ -11,6 +11,15 @@ TODO - tests with other database and drivers? - rethink record classes? we just really want a row conversion function? - add documentation about docker runs. +- allow tagging queries, eg whether it can be cached + +? on ? +------ + +- improve Makefile. +- warn on probable mission operation. +- add *psycopg2* to CI. +- improve documentation. 12.2 on 2024-10-02 ------------------ diff --git a/pyproject.toml b/pyproject.toml index 390a87f9..ebc3c98e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,8 @@ dev-postgres = [ "pytest-postgresql", "asyncpg; python_version < '3.13' and implementation_name != 'pypy'", "psycopg>=3", - "psycopg2; python_version < '3.13' and implementation_name != 'pypy'", + # 2.9.10 needed for 3.13 + "psycopg2 >= 2.9.10; implementation_name != 'pypy'", "pygresql", "pg8000" ] diff --git a/tests/blogdb/sql/misc/misc.sql b/tests/blogdb/sql/misc/misc.sql index 98add9da..c1da5edd 100644 --- a/tests/blogdb/sql/misc/misc.sql +++ b/tests/blogdb/sql/misc/misc.sql @@ -24,3 +24,6 @@ SELECT :numerator % :denominator AS modulo; -- name: square$ select :val::int * :val::int as squared; + +-- name: not_a_select +INSERT INTO Foo VALUES (1);