fix: _where() renders None conditions as IS NULL instead of = NULL
col = $n bound to NULL never matches in sql, so get/get_one/exists/delete silently missed every row filtered on a None value despite insert() writing NULL fine. Kept in lockstep with the mysql lib's identical fix. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -10,18 +10,18 @@ a sibling of the `mongo` lib. Class is **`PsqlDB`**.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.2
|
psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.3
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.2"
|
pip install "psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.3"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pulls `asyncpg`.
|
Pulls `asyncpg`.
|
||||||
|
|
||||||
Drop the `@v0.1.2` suffix from the line above to install the latest unpinned.
|
Drop the `@v0.1.3` suffix from the line above to install the latest unpinned.
|
||||||
|
|
||||||
## The two-layer API
|
## The two-layer API
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "psql"
|
name = "psql"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
description = "async postgres wrapper over asyncpg: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
description = "async postgres wrapper over asyncpg: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
+12
-4
@@ -373,13 +373,21 @@ class _Transaction:
|
|||||||
def _where(conditions: Optional[Dict[str, Any]]) -> tuple:
|
def _where(conditions: Optional[Dict[str, Any]]) -> tuple:
|
||||||
"""build a parameterized `WHERE col = $1 AND ...` clause + the params list
|
"""build a parameterized `WHERE col = $1 AND ...` clause + the params list
|
||||||
|
|
||||||
returns ("", []) when there are no conditions. equality only.
|
returns ("", []) when there are no conditions. equality only. a None value renders as
|
||||||
|
`col IS NULL` (not `col = $n` bound to NULL, which sql never matches) and does not
|
||||||
|
consume a placeholder.
|
||||||
"""
|
"""
|
||||||
if not conditions:
|
if not conditions:
|
||||||
return "", []
|
return "", []
|
||||||
cols = list(conditions.keys())
|
parts = []
|
||||||
clause = " AND ".join(f"{_quote_ident(c)} = ${i + 1}" for i, c in enumerate(cols))
|
params = []
|
||||||
return f" WHERE {clause}", list(conditions.values())
|
for col, val in conditions.items():
|
||||||
|
if val is None:
|
||||||
|
parts.append(f"{_quote_ident(col)} IS NULL")
|
||||||
|
else:
|
||||||
|
params.append(val)
|
||||||
|
parts.append(f"{_quote_ident(col)} = ${len(params)}")
|
||||||
|
return f" WHERE {' AND '.join(parts)}", params
|
||||||
|
|
||||||
|
|
||||||
def _status_count(status: str) -> int:
|
def _status_count(status: str) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user