1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 03:24:20 +00:00

💥 Remove Alchemist class, create a few utility functions

This commit is contained in:
Steffo 2020-11-01 02:26:27 +01:00
parent bf949fed55
commit 8986897292
2 changed files with 31 additions and 23 deletions

View file

@ -1,23 +1 @@
from royalnet.typing import * from .func import *
import sqlalchemy as sa
import sqlalchemy.orm as saorm
__all__ = (
"Alchemist",
)
class Alchemist:
"""The Alchemist module connects to a relational database with SQLAlchemy."""
def __init__(self,
engine_args: Iterable[Any],
engine_kwargs: Mapping[str, Any]):
self.engine: sa.engine.Engine = sa.create_engine(*engine_args, **engine_kwargs)
self.Session: Union[saorm.sessionmaker, Type[saorm.Session]] = saorm.sessionmaker(bind=self.engine)
def add_metadata(self, metadata: sa.MetaData):
"""Bind a MetaData object to the engine, and create all tables linked with it."""
metadata.bind = self.engine
metadata.create_all()

View file

@ -0,0 +1,30 @@
from ..typing import *
import sqlalchemy
def ieq(one, two):
"""
Create a case-insensitive equality filter for SQLAlchemy. ::
lower(one) == lower(two)
"""
return sqlalchemy.func.lower(one) == sqlalchemy.func.lower(two)
def ineq(one, two):
"""
Create a case-insensitive inequality filter for SQLAlchemy. ::
lower(one) != lower(two)
"""
return sqlalchemy.func.lower(one) != sqlalchemy.func.lower(two)
__all__ = (
"ieq",
"ineq",
)