Skip to content

Commit

Permalink
Add methods to_sync and to_async (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet authored Jan 31, 2024
1 parent bb33ec3 commit 1efa370
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions astrapy/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def __init__(
def __repr__(self) -> str:
return f'Astra DB Collection[name="{self.collection_name}", endpoint="{self.astra_db.base_url}"]'

def to_async(self) -> AsyncAstraDBCollection:
return AsyncAstraDBCollection(
astra_db=self.astra_db.to_async(), collection_name=self.collection_name
)

def _request(
self,
method: str = http_methods.POST,
Expand Down Expand Up @@ -1015,6 +1020,11 @@ def __init__(
def __repr__(self) -> str:
return f'Astra DB Collection[name="{self.collection_name}", endpoint="{self.astra_db.base_url}"]'

def to_sync(self) -> AstraDBCollection:
return AstraDBCollection(
astra_db=self.astra_db.to_sync(), collection_name=self.collection_name
)

async def _request(
self,
method: str = http_methods.POST,
Expand Down Expand Up @@ -1889,6 +1899,15 @@ def __init__(
def __repr__(self) -> str:
return f'Astra DB[endpoint="{self.base_url}"]'

def to_async(self) -> AsyncAstraDB:
return AsyncAstraDB(
token=self.token,
api_endpoint=self.base_url,
api_path=self.api_path,
api_version=self.api_version,
namespace=self.namespace,
)

def _request(
self,
method: str = http_methods.POST,
Expand Down Expand Up @@ -2124,6 +2143,15 @@ async def __aexit__(
) -> None:
await self.client.aclose()

def to_sync(self) -> AstraDB:
return AstraDB(
token=self.token,
api_endpoint=self.base_url,
api_path=self.api_path,
api_version=self.api_version,
namespace=self.namespace,
)

async def _request(
self,
method: str = http_methods.POST,
Expand Down

0 comments on commit 1efa370

Please sign in to comment.