Skip to content

Commit

Permalink
Merge pull request #18 from tarsil/fix/co
Browse files Browse the repository at this point in the history
Fix/co
  • Loading branch information
tarsil authored Nov 20, 2023
2 parents a1ba537 + 7f5b7a9 commit 9bf210a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
12 changes: 8 additions & 4 deletions .github/dependbot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: 2
updates:
- package-ecosystem: "pip"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "github-actions"
interval: "daily"
commit-message:
prefix:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: monthly
interval: "daily"
commit-message:
prefix:
22 changes: 19 additions & 3 deletions mongoz/core/connection/database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List
from typing import Any, Dict, List, Optional

from bson import CodecOptions, UuidRepresentation
from motor.motor_asyncio import AsyncIOMotorDatabase

from mongoz.core.connection.collections import Collection
Expand All @@ -10,12 +11,27 @@ class Database:
MongoDB database object referencing Motor database
"""

def __init__(self, name: str, database: AsyncIOMotorDatabase) -> None:
def __init__(
self,
name: str,
database: AsyncIOMotorDatabase,
codec_options: Optional[Dict[str, Any]] = None,
) -> None:
self._db = database
self.name = name

self._codec_options = (
codec_options
if codec_options
else {"uuid_representation": UuidRepresentation.STANDARD}
)

@property
def codec_options(self) -> CodecOptions:
return CodecOptions(**self._codec_options)

def get_collection(self, name: str) -> Collection:
collection = self._db.get_collection(name)
collection = self._db.get_collection(name, codec_options=self.codec_options)
return Collection(name, collection=collection)

async def get_collections(self) -> List[Collection]:
Expand Down

0 comments on commit 9bf210a

Please sign in to comment.