Skip to content

Commit

Permalink
Interface for Connections with DSN
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Feb 11, 2022
1 parent cb48eb9 commit d199195
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
34 changes: 31 additions & 3 deletions asyncdb/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class ConnectionBackend(ABC):

def __init__(
self,
dsn: str = '',
loop: asyncio.AbstractEventLoop = None,
params: Dict[Any, Any] = {},
**kwargs
Expand Down Expand Up @@ -251,6 +250,37 @@ async def __aexit__(self, exc_type, exc, tb):
await self.close()


class ConnectionDSNBackend(ConnectionBackend):
"""
Interface for Databases with DSN Support.
"""

def __init__(
self,
dsn: str = '',
loop: asyncio.AbstractEventLoop = None,
params: Dict[Any, Any] = {},
**kwargs
) -> None:
super(ConnectionDSNBackend, self).__init__(
loop, params, **kwargs
)
if dsn:
self._dsn = dsn
else:
self._dsn = self.create_dsn(params)

def create_dsn(self, params):
try:
return self._dsn.format(**params)
except Exception as err:
self._logger.exception(err)
return None

def get_dsn(self):
return self._dsn


class TransactionBackend(ABC):
"""
Interface for Drivers Support transactions.
Expand All @@ -273,8 +303,6 @@ async def transaction_start(
"""
Starts a Transaction.
"""
if not self._connection:
await self.connection()
self._transaction = self.transaction(options)

@abstractmethod
Expand Down
23 changes: 23 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
site_name: AsyncDB
site_description: Asyncio-based database connectors for Python.

theme:
name: 'material'

repo_name: phenobarbital/asyncdb
repo_url: https://github.com/phenobarbital/asyncdb
# edit_uri: ""

nav:
- Introduction: 'index.md'
- Database Queries: 'database_queries.md'
- Connections & Transactions: 'connections_and_transactions.md'
- Cursors & Prepared Statements: 'cursors.md'
- Tests & Migrations: 'tests_and_migrations.md'
- Contributing: 'contributing.md'

markdown_extensions:
- mkautodoc
- admonition
- pymdownx.highlight
- pymdownx.superfences

0 comments on commit d199195

Please sign in to comment.