I am new to Pyramid and SQLAlchemy. I am working on a Pyramid Python project with SQLAlchemy. The following is a simple model. How could I use this with different circuits at runtime? This will be the PostgreSQL database database. Right now, βpublicβ is hard-coded into a declarative base model. I would need the opportunity to use the same model with a different circuit. What is the best approach? If I did not miss this, the documentation in SQLAlchemy seemed confusing to me.
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, BigInteger __all__ = [ "LoadTender" ] __all__.sort() Base = declarative_base() class LoadTender(Base): __tablename__ = "load_tenders" __table_args__ = {"schema": "public"} id = Column("pkey", BigInteger, primary_key=True) def __repr__(self): return "" % self.id
EDIT: I seem to have solved my problem, I am updating a snippet to show what I did below.
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, BigInteger __all__ = [ "LoadTender" ] __all__.sort() Base = declarative_base() class ClientMixin(object): __table_args__ = {"schema": "client_schema_name"} class LoadTenderMixin(object): __tablename__ = "load_tenders" id = Column("pkey", BigInteger, primary_key=True) def __repr__(self): return "" % self.id class ClientLoadTender(LoadTenderMixin, ClientMixin, Base): pass
source share