Skip to content

Commit

Permalink
* feat: drop deprectated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos authored Jul 25, 2024
1 parent 8eb34bb commit a3ec56e
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 1,555 deletions.
2 changes: 0 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ docker compose up postgres

## Example for `aiohttp` server

The example `aiohttp_example.py` is using older interface with `Manager` class. The `Manager`
will be deprecated in v1.0 but we aim to support it until that milestone.

Define database connection settings if needed, environment variables used:

Expand Down
22 changes: 0 additions & 22 deletions peewee_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
from importlib.metadata import version

from playhouse.db_url import register_database

from peewee_async_compat import count, execute, prefetch, scalar, savepoint, atomic, transaction, Manager
from .aio_model import aio_prefetch, AioModel
from .connection import connection_context
from .databases import (
PooledPostgresqlDatabase,
PooledPostgresqlExtDatabase,
PooledMySQLDatabase,
PostgresqlDatabase,
MySQLDatabase,
PostgresqlExtDatabase
)
from .pool import PostgresqlPoolBackend, MysqlPoolBackend
from .transactions import Transaction
Expand All @@ -44,25 +39,8 @@
'connection_context',
'PostgresqlPoolBackend',
'MysqlPoolBackend',

# Compatibility API (deprecated in v1.0 release)
'Manager',
'execute',
'count',
'scalar',
'prefetch',
'atomic',
'transaction',
'savepoint',
]

register_database(PooledPostgresqlDatabase, 'postgres+pool+async', 'postgresql+pool+async')
register_database(PooledPostgresqlExtDatabase, 'postgresext+pool+async', 'postgresqlext+pool+async')
register_database(PooledMySQLDatabase, 'mysql+pool+async')


# DEPRECATED Databases

register_database(PostgresqlDatabase, 'postgres+async', 'postgresql+async')
register_database(MySQLDatabase, 'mysql+async')
register_database(PostgresqlExtDatabase, 'postgresext+async', 'postgresqlext+async')
148 changes: 0 additions & 148 deletions peewee_async/databases.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import contextlib
import logging
import warnings
from typing import Type, Optional, Any, AsyncIterator, Iterator

import peewee
from playhouse import postgres_ext as ext

from peewee_async_compat import _patch_query_with_compat_methods, savepoint
from .connection import connection_context, ConnectionContextManager
from .pool import PoolBackend, PostgresqlPoolBackend, MysqlPoolBackend
from .transactions import Transaction
Expand Down Expand Up @@ -119,69 +117,11 @@ async def aio_execute(self, query, fetch_results=None):
don't need to close cursor It will be closed automatically.
:return: result depends on query type, it's the same as for sync `query.execute()`
"""
# To make `Database.aio_execute` compatible with peewee's sync queries we
# apply optional patching, it will do nothing for Aio-counterparts:
_patch_query_with_compat_methods(query, None)
ctx = self.get_sql_context()
sql, params = ctx.sql(query).query()
fetch_results = fetch_results or getattr(query, 'fetch_results', None)
return await self.aio_execute_sql(sql, params, fetch_results=fetch_results)

#### Deprecated methods ####
def __setattr__(self, name, value) -> None:
if name == 'allow_sync':
warnings.warn(
"`.allow_sync` setter is deprecated, use either the "
"`.allow_sync()` context manager or `.set_allow_sync()` "
"method.", DeprecationWarning)
self._allow_sync = value
else:
super().__setattr__(name, value)

def atomic_async(self) -> Any:
"""Similar to peewee `Database.atomic()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()

def savepoint_async(self, sid=None) -> Any:
"""Similar to peewee `Database.savepoint()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`savepoint` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return savepoint(self, sid=sid)

async def connect_async(self) -> None:
warnings.warn(
"`connect_async` is deprecated, use `aio_connect` instead.",
DeprecationWarning
)
await self.aio_connect()

async def close_async(self) -> None:
warnings.warn(
"`close_async` is deprecated, use `aio_close` instead.",
DeprecationWarning
)
await self.aio_close()

def transaction_async(self) -> Any:
"""Similar to peewee `Database.transaction()` method, but returns
asynchronous context manager.
"""
warnings.warn(
"`atomic_async` is deprecated, use `aio_atomic` instead.",
DeprecationWarning
)
return self.aio_atomic()


class AioPostgresqlMixin(AioDatabase):
"""Mixin for `peewee.PostgresqlDatabase` providing extra methods
Expand Down Expand Up @@ -229,13 +169,6 @@ class PooledPostgresqlDatabase(AioPostgresqlMixin, peewee.PostgresqlDatabase):
def init(self, database: Optional[str], **kwargs: Any) -> None:
self.min_connections = kwargs.pop('min_connections', 1)
self.max_connections = kwargs.pop('max_connections', 20)
connection_timeout = kwargs.pop('connection_timeout', None)
if connection_timeout is not None:
warnings.warn(
"`connection_timeout` is deprecated, use `connect_timeout` instead.",
DeprecationWarning
)
kwargs['connect_timeout'] = connection_timeout
super().init(database, **kwargs)
self.init_async()

Expand Down Expand Up @@ -265,12 +198,6 @@ def init(self, database: Optional[str], **kwargs: Any) -> None:
self.min_connections = kwargs.pop('min_connections', 1)
self.max_connections = kwargs.pop('max_connections', 20)
connection_timeout = kwargs.pop('connection_timeout', None)
if connection_timeout is not None:
warnings.warn(
"`connection_timeout` is deprecated, use `connect_timeout` instead.",
DeprecationWarning
)
kwargs['connect_timeout'] = connection_timeout
super().init(database, **kwargs)
self.init_async(
enable_json=True,
Expand Down Expand Up @@ -314,78 +241,3 @@ def connect_params_async(self):
'autocommit': True,
})
return kwargs


# DEPRECATED Databases


class PostgresqlDatabase(AioPostgresqlMixin, peewee.PostgresqlDatabase):
"""PosgreSQL database driver providing **single drop-in sync** connection
and **single async connection** interface.
Example::
database = PostgresqlDatabase('test')
See also:
http://peewee.readthedocs.io/en/latest/peewee/api.html#PostgresqlDatabase
"""
def init(self, database: Optional[str], **kwargs: Any) -> None:
warnings.warn(
"`PostgresqlDatabase` is deprecated, use `PooledPostgresqlDatabase` instead.",
DeprecationWarning
)
self.min_connections = 1
self.max_connections = 1
super().init(database, **kwargs)
self.init_async()


class MySQLDatabase(PooledMySQLDatabase):
"""MySQL database driver providing **single drop-in sync** connection
and **single async connection** interface.
Example::
database = MySQLDatabase('test')
See also:
http://peewee.readthedocs.io/en/latest/peewee/api.html#MySQLDatabase
"""
def init(self, database: Optional[str], **kwargs: Any) -> None:
warnings.warn(
"`MySQLDatabase` is deprecated, use `PooledMySQLDatabase` instead.",
DeprecationWarning
)
super().init(database, **kwargs)
self.min_connections = 1
self.max_connections = 1


class PostgresqlExtDatabase(AioPostgresqlMixin, ext.PostgresqlExtDatabase):
"""PosgreSQL database extended driver providing **single drop-in sync**
connection and **single async connection** interface.
JSON fields support is always enabled, HStore supports is enabled by
default, but can be disabled with ``register_hstore=False`` argument.
Example::
database = PostgresqlExtDatabase('test', register_hstore=False)
See also:
https://peewee.readthedocs.io/en/latest/peewee/playhouse.html#PostgresqlExtDatabase
"""

def init(self, database: Optional[str], **kwargs: Any) -> None:
warnings.warn(
"`PostgresqlExtDatabase` is deprecated, use `PooledPostgresqlExtDatabase` instead.",
DeprecationWarning
)
self.min_connections = 1
self.max_connections = 1
super().init(database, **kwargs)
self.init_async(
enable_json=True,
enable_hstore=self._register_hstore
)
Loading

0 comments on commit a3ec56e

Please sign in to comment.