object_based_docstore_approach #68

Merged
brian merged 64 commits from object_based_docstore_approach into main 2025-04-16 00:03:25 +02:00
4 changed files with 12 additions and 12 deletions
Showing only changes of commit 88a20c4b0b - Show all commits
+4 -4
View File
@@ -40,7 +40,7 @@ class DocstoreMongo(DocstoreInterface):
mongo_database = str(os.getenv('MONGO_DB'))
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
# connect client
client = MongoClient(mongo_endpoint)
client: MongoClient = MongoClient(mongo_endpoint)
database = client[mongo_database]
collection = database[mongo_collection]
# set unique index on 'name'
@@ -53,9 +53,9 @@ class DocstoreMongo(DocstoreInterface):
def close(self) -> None:
"""Close connection to Mongo server."""
self._client.close()
self._client = None
self._database = None
self._collection = None
self._client = None # type: ignore
self._database = None # type: ignore
self._collection = None # type: ignore
def __enter__(self) -> DocstoreMongo:
self.connect()
@@ -39,7 +39,7 @@ class MongoImplementation(DatabaseInterface):
mongo_database = str(os.getenv('MONGO_DB'))
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
# connect client
client = MongoClient(mongo_endpoint)
client: MongoClient = MongoClient(mongo_endpoint)
database = client[mongo_database]
collection = database[mongo_collection]
# set unique index on 'name'
@@ -52,9 +52,9 @@ class MongoImplementation(DatabaseInterface):
def close(self) -> None:
"""Close connection to Mongo server."""
self._client.close()
self._client = None
self._database = None
self._collection = None
self._client = None # type: ignore
self._database = None # type: ignore
self._collection = None # type: ignore
def connected(self) -> bool:
"""Check connection to Mongo."""
@@ -34,11 +34,11 @@ class VisualCommunicationRepository(VisualCommunicationInterface, MongoImplement
"""Put visual communication data."""
assert isinstance(data, VisualCommunicationData)
# convert to dict
data = data.model_dump(mode='json')
data_dict: dict = data.model_dump(mode='json')
# build query
query = {'name': data['name']}
query = {'name': data.name}
# save to mongo
self._save(data, query)
self._save(data_dict, query)
def remove_data(self, name: str) -> None:
"""Remove visual communication data."""
@@ -328,7 +328,7 @@ def raw_mongo_client(
mongo_endpoint = str(os.getenv('MONGO_ENDPOINT'))
mongo_database = str(os.getenv('MONGO_DB'))
# connect client
client = MongoClient(mongo_endpoint)
client: MongoClient = MongoClient(mongo_endpoint)
_ = client[mongo_database]
# expose client
yield client