EngineStrategy
is a class within the sqlalchemy.engine.strategies
module of the SQLAlchemy project.
MockEngineStrategy
is another callable from the sqlalchemy.engine.strategies
package with code examples.
GINO (project documentation and PyPI package information) is an object-relational mapper (ORM) built on SQLAlchemy that is non-blocking and therefore designed to work properly with asynchronously-run code, for example, an application written with asyncio.
GINO is open sourced under the BSD License.
GINO / src/gino / strategies.py
# strategies.py
import asyncio
from copy import copy
from sqlalchemy.engine import url
from sqlalchemy import util
from sqlalchemy.engine.strategies import EngineStrategy
from .engine import GinoEngine
class GinoStrategy(EngineStrategy):
name = "gino"
engine_cls = GinoEngine
async def create(self, name_or_url, loop=None, **kwargs):
engine_cls = self.engine_cls
u = url.make_url(name_or_url)
if loop is None:
loop = asyncio.get_event_loop()
if u.drivername in {"postgresql", "postgres"}:
u = copy(u)
u.drivername = "postgresql+asyncpg"
dialect_cls = u.get_dialect()
pop_kwarg = kwargs.pop
dialect_args = {}
for k in util.get_cls_kwargs(dialect_cls).union(
getattr(dialect_cls, "init_kwargs", set())
):
if k in kwargs:
dialect_args[k] = pop_kwarg(k)
## ... source file continues with no further EngineStrategy examples...