3 Commits
Author SHA1 Message Date
dsql 1d55efbcdd chore: ignore .claude/ dir (CLAUDE.md now lives under .claude/)
Signed-off-by: disqualifier <dev@disqualifier.me>
2026-06-29 21:55:13 -04:00
dsql fe8f2da480 fix: annotate database property return type (AsyncIOMotorDatabase)
Signed-off-by: disqualifier <dev@disqualifier.me>
2026-06-29 21:35:22 -04:00
dsql 9ad3458cf9 fix: align push helpers to matched_count for success-contract consistency (v0.1.3)
mongo-1: document_push_array and document_push_and_set still returned modified_count>0
while the v0.1.2 wave moved the sibling single-doc update helpers to matched_count>0.
$push always mutates so the two agree in practice (no reachable behavioral change), but
the helpers now match the documented 'True when a document matched' contract uniformly.

sibling-grep: zero consumers of either push helper.
Signed-off-by: disqualifier <dev@disqualifier.me>
2026-06-29 20:48:08 -04:00
4 changed files with 20 additions and 11 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# claude # claude
CLAUDE.md .claude/
# python # python
__pycache__/ __pycache__/
+3 -3
View File
@@ -8,18 +8,18 @@ helpers for the common paths, with a raw escape hatch for everything else.
`requirements.txt`: `requirements.txt`:
``` ```
mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.2 mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.3
``` ```
Direct: Direct:
```bash ```bash
pip install "mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.2" pip install "mongo @ git+ssh://git@git.rethinkstudios.io/rethink-public/mongo.git@v0.1.3"
``` ```
Requires `motor` and `pymongo` (pulled transitively). Requires `motor` and `pymongo` (pulled transitively).
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.
## Usage ## Usage
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "mongo" name = "mongo"
version = "0.1.2" version = "0.1.3"
description = "async mongodb wrapper over motor with a raw escape hatch" description = "async mongodb wrapper over motor with a raw escape hatch"
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = [ dependencies = [
+15 -6
View File
@@ -27,7 +27,7 @@ import logging
from typing import Any, List, Optional from typing import Any, List, Optional
from pymongo import ReturnDocument from pymongo import ReturnDocument
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorCollection from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorCollection, AsyncIOMotorDatabase
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -48,7 +48,7 @@ class Mongo:
return self._db[name] return self._db[name]
@property @property
def database(self): def database(self) -> AsyncIOMotorDatabase:
"""raw motor database handle""" """raw motor database handle"""
return self._db return self._db
@@ -361,10 +361,15 @@ class Mongo:
async def document_push_array( async def document_push_array(
self, collection: str, target: dict, array: str, value: Any self, collection: str, target: dict, array: str, value: Any
) -> bool: ) -> bool:
"""$push a value onto an array field""" """$push a value onto an array field
returns True when a document matched (consistent with the other single-doc
update helpers); $push always mutates, so matched_count and modified_count
agree here in practice.
"""
try: try:
response = await self._db[collection].update_one(target, {"$push": {array: value}}) response = await self._db[collection].update_one(target, {"$push": {array: value}})
return response.modified_count > 0 return response.matched_count > 0
except Exception: except Exception:
log.exception(f"db.document_push_array() on {collection}") log.exception(f"db.document_push_array() on {collection}")
return False return False
@@ -373,13 +378,17 @@ class Mongo:
self, collection: str, target: dict, array: str, value: Any, self, collection: str, target: dict, array: str, value: Any,
field_to_set: str, set_value: Any, field_to_set: str, set_value: Any,
) -> bool: ) -> bool:
"""$push to an array and $set a field in one update""" """$push to an array and $set a field in one update
returns True when a document matched (consistent with the other single-doc
update helpers).
"""
try: try:
response = await self._db[collection].update_one( response = await self._db[collection].update_one(
target, target,
{"$push": {array: value}, "$set": {field_to_set: set_value}}, {"$push": {array: value}, "$set": {field_to_set: set_value}},
) )
return response.modified_count > 0 return response.matched_count > 0
except Exception: except Exception:
log.exception(f"db.document_push_and_set() on {collection}") log.exception(f"db.document_push_and_set() on {collection}")
return False return False