You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
I try to use package and fail.
I have looked in #21 , #12
My orm classes are in one module orm.py.
importdatetimefromsqlalchemy.ext.declarativeimportdeclarative_base, declared_attrfromsqlalchemyimport (
create_engine,
text,
Column,
Integer,
Text,
ForeignKey,
LargeBinary,
Date,
DateTime,
Boolean
)
fromsqlalchemy.ormimportrelationship, class_mapper, sessionmaker, excfromsqlalchemy.dialects.postgresqlimportENUMfromstubsimportcyclop_pb2fromcontextlibimportcontextmanagerimportosimportimportlibfrompostgresql_auditimportversioning_managerimportsqlalchemyassa# Enum# A role of the user.role= ('USER', 'ADMIN')
Role=ENUM(*role, name="role")
classBase(object):
@declared_attrdef__tablename__(cls):
"""Give every class a simple table name based on class name"""returncls.__name__.lower()
id=Column(Integer, primary_key=True)
Base=declarative_base(cls=Base)
versioning_manager.init(Base)
classUsers(Base):
"""Cyclop user. Users:Sessions = 1:many. A one to many bidirectional relationship of an Users to a Sessions. A one to many relationship places a foreign key on the child table referencing the parent. Child will get a parent attribute with many-to-one semantics. """__versioned__= {}
login=Column(Text, nullable=False, unique=True)
password=Column(Text, nullable=False)
# A role of the user.role=Column(Role, nullable=False)
alias=Column(Text)
archive=Column(Boolean, nullable=False)
sessions=relationship("Sessions", backref="users",
cascade="all, delete, delete-orphan", single_parent=True)
classSessions(Base):
"""A session for client Users give the token. Users:Sessions = 1:many. """__versioned__= {}
# A link to the one and only one Users instance.user_id=Column(Integer, ForeignKey('users.id'), nullable=False)
token=Column(Text, nullable=False)
start_time=Column(DateTime, nullable=False)
end_time=Column(DateTime)
classORM():
"""Provide a transactional scope context for session use. To create db 'test' use as context: with ORM('test') as orm: orm.create_declarative_base(Base) """def__init__(self, db='cyclop'):
"""Init don`t do much as __enter__() take role of context creation. :param db: A database name. """self.db=dbdefcreate(self):
"""Create engine."""self.engine=create_engine(
'postgresql://cyclop:cyclop@localhost/{0}'.format(self.db),
echo=True)
"""Create SQLAlchemy session."""Session=sessionmaker(bind=self.engine)
self.session=Session()
sa.orm.configure_mappers() # <-- Important# Removing these lines prevents audit trailing to work because the `audit_table` trigger is never attached.tables=Base.metadata.tablesversioning_manager.audit_table(tables['users'])
Base.metadata.create_all(self.engine, checkfirst=True)
Hello!
I try to use package and fail.
I have looked in #21 , #12
My orm classes are in one module orm.py.
Unittest
Output:
The text was updated successfully, but these errors were encountered: