Closed language-cat closed 6 months ago
@techoner @Nekotoxin
@language-cat It seems that the function create_async_engine
does not support specifying the ‘schema’ parameter.
@language-cat hi, you can specify the ‘schema’ in a SQLAlchemy model class.
For example:
Base = declarative_base()
class CasbinRule(Base):
__tablename__ = "casbin_rule"
__table_args__ = {'schema': 'your_schema'}
id = Column(Integer, primary_key=True)
ptype = Column(String(255))
v0 = Column(String(255))
v1 = Column(String(255))
v2 = Column(String(255))
v3 = Column(String(255))
v4 = Column(String(255))
v5 = Column(String(255))
def __str__(self):
arr = [self.ptype]
for v in (self.v0, self.v1, self.v2, self.v3, self.v4, self.v5):
if v is None:
break
arr.append(v)
return ", ".join(arr)
def __repr__(self):
return '<CasbinRule {}: "{}">'.format(self.id, str(self))
async def get_enforcer():
engine = create_async_engine(
"postgresql+asyncpg://user:password@hostname/dbname",
echo=True,
)
adapter = Adapter(engine, db_class=CasbinRule)
await adapter.create_table()
e = casbin.AsyncEnforcer("rbac_model.conf", adapter)
await e.load_policy()
return e
Closed as resolved
this is my code:
how to set schema when using create_async_engine