Skip to content

Commit

Permalink
chore: add warnings to the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed May 13, 2024
1 parent b8d42f6 commit f7db55e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions peewee_async_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ async def my_async_func():
All will return `MyModel` instance with `id = 1`
"""
warnings.warn(
"`get` method is deprecated, use `AioModel.aio_get` instead.",
DeprecationWarning
)
await self.connect()

if isinstance(source_, peewee.Query):
Expand All @@ -252,6 +256,10 @@ async def my_async_func():

async def create(self, model_, **data):
"""Create a new object saved to database."""
warnings.warn(
"`create` method is deprecated, use `AioModel.aio_create` instead.",
DeprecationWarning
)
obj = model_(**data)
query = model_.insert(**dict(obj.__data__))

Expand All @@ -277,6 +285,10 @@ async def get_or_create(self, model_, defaults=None, **kwargs):

async def get_or_none(self, model_, *args, **kwargs):
"""Try to get an object and return None if it doesn't exist."""
warnings.warn(
"`get_or_none` method is deprecated, use `AioModel.aio_get_or_none` instead.",
DeprecationWarning
)
try:
return (await self.get(model_, *args, **kwargs))
except model_.DoesNotExist:
Expand Down Expand Up @@ -345,6 +357,10 @@ async def create_or_get(self, model_, **kwargs):

async def execute(self, query):
"""Execute query asyncronously."""
warnings.warn(
"`execute` method is deprecated, use `AioModel.aio_execute` or database.aio_execute instead.",
DeprecationWarning
)
return await self.database.aio_execute(query)

async def prefetch(self, query, *subqueries, prefetch_type=peewee.PREFETCH_TYPE.JOIN):
Expand Down

0 comments on commit f7db55e

Please sign in to comment.