This commit is contained in:
@@ -40,7 +40,7 @@ class DocstoreMongo(DocstoreInterface):
|
|||||||
mongo_database = str(os.getenv('MONGO_DB'))
|
mongo_database = str(os.getenv('MONGO_DB'))
|
||||||
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
|
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
|
||||||
# connect client
|
# connect client
|
||||||
client = MongoClient(mongo_endpoint)
|
client: MongoClient = MongoClient(mongo_endpoint)
|
||||||
database = client[mongo_database]
|
database = client[mongo_database]
|
||||||
collection = database[mongo_collection]
|
collection = database[mongo_collection]
|
||||||
# set unique index on 'name'
|
# set unique index on 'name'
|
||||||
@@ -53,9 +53,9 @@ class DocstoreMongo(DocstoreInterface):
|
|||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
"""Close connection to Mongo server."""
|
"""Close connection to Mongo server."""
|
||||||
self._client.close()
|
self._client.close()
|
||||||
self._client = None
|
self._client = None # type: ignore
|
||||||
self._database = None
|
self._database = None # type: ignore
|
||||||
self._collection = None
|
self._collection = None # type: ignore
|
||||||
|
|
||||||
def __enter__(self) -> DocstoreMongo:
|
def __enter__(self) -> DocstoreMongo:
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class MongoImplementation(DatabaseInterface):
|
|||||||
mongo_database = str(os.getenv('MONGO_DB'))
|
mongo_database = str(os.getenv('MONGO_DB'))
|
||||||
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
|
mongo_collection = str(os.getenv('MONGO_COLLECTION'))
|
||||||
# connect client
|
# connect client
|
||||||
client = MongoClient(mongo_endpoint)
|
client: MongoClient = MongoClient(mongo_endpoint)
|
||||||
database = client[mongo_database]
|
database = client[mongo_database]
|
||||||
collection = database[mongo_collection]
|
collection = database[mongo_collection]
|
||||||
# set unique index on 'name'
|
# set unique index on 'name'
|
||||||
@@ -52,9 +52,9 @@ class MongoImplementation(DatabaseInterface):
|
|||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
"""Close connection to Mongo server."""
|
"""Close connection to Mongo server."""
|
||||||
self._client.close()
|
self._client.close()
|
||||||
self._client = None
|
self._client = None # type: ignore
|
||||||
self._database = None
|
self._database = None # type: ignore
|
||||||
self._collection = None
|
self._collection = None # type: ignore
|
||||||
|
|
||||||
def connected(self) -> bool:
|
def connected(self) -> bool:
|
||||||
"""Check connection to Mongo."""
|
"""Check connection to Mongo."""
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ class VisualCommunicationRepository(VisualCommunicationInterface, MongoImplement
|
|||||||
"""Put visual communication data."""
|
"""Put visual communication data."""
|
||||||
assert isinstance(data, VisualCommunicationData)
|
assert isinstance(data, VisualCommunicationData)
|
||||||
# convert to dict
|
# convert to dict
|
||||||
data = data.model_dump(mode='json')
|
data_dict: dict = data.model_dump(mode='json')
|
||||||
# build query
|
# build query
|
||||||
query = {'name': data['name']}
|
query = {'name': data.name}
|
||||||
# save to mongo
|
# save to mongo
|
||||||
self._save(data, query)
|
self._save(data_dict, query)
|
||||||
|
|
||||||
def remove_data(self, name: str) -> None:
|
def remove_data(self, name: str) -> None:
|
||||||
"""Remove visual communication data."""
|
"""Remove visual communication data."""
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ def raw_mongo_client(
|
|||||||
mongo_endpoint = str(os.getenv('MONGO_ENDPOINT'))
|
mongo_endpoint = str(os.getenv('MONGO_ENDPOINT'))
|
||||||
mongo_database = str(os.getenv('MONGO_DB'))
|
mongo_database = str(os.getenv('MONGO_DB'))
|
||||||
# connect client
|
# connect client
|
||||||
client = MongoClient(mongo_endpoint)
|
client: MongoClient = MongoClient(mongo_endpoint)
|
||||||
_ = client[mongo_database]
|
_ = client[mongo_database]
|
||||||
# expose client
|
# expose client
|
||||||
yield client
|
yield client
|
||||||
|
|||||||
Reference in New Issue
Block a user