Access to a RecordMap with SQLAlchemy
Hi,
I'm trying to access to my datas stored in a RecordMap from SQLAlchemy, and I need to access to any tables already created before using SQLAlchemy.
Here is some part of my code :
TestBase:
class TestBase(DeclarativeBase):
CreatedAt: Mapped[int] = mapped_column(TIMESTAMP, default=func.now())
UpdatedAt: Mapped[int] = mapped_column(TIMESTAMP, default=func.now(), onupdate=func.current_timestamp())
PythonPython
Engine creation and entities binding :
bases = {
"TEST": TestBase.metadata.create_all,
}
def create_engine_and_session(namespace: str) -> Session:
engine: Engine = create_engine(f"iris://_SYSTEM:SYS@localhost:1972/{namespace}") # create_engine(f'iris+emb:///{namespace}')
metadata = MetaData()
metadata.reflect(engine)
bases[namespace](engine)
OrmSession = sessionmaker(bind=engine)
sessions[namespace] = OrmSession()
return sessions[namespace]
PythonPython
My RecordMap entity :
class BastideRecord(TestBase):
__tablename__ = "User_BastideRecord.Record"
__table_args__ = {"extend_existing": True}
__versioned__ = {}
ID1: Mapped[int] = mapped_column(Integer, primary_key=True)
Statut: Mapped[str] = mapped_column(String(999))
Id: Mapped[str] = mapped_column(String(50))
PythonPython
Each part of my code are in different files, the "User_BastideRecord.Record" RecordMap is already created but when I create my SQLAlchemy engine, it will try to create the RecordMap table. Here is the error log I have :
: ERROR #5002: ObjectScript error: OnInit+4 ^Grongier.PEX.BusinessProcess.1 ^8^ do ..%class."_dispatch_on_init"($this) *<class 'sqlalchemy.exc.DatabaseError'>: (intersystems_iris.dbapi._DBAPI.DatabaseError) [SQLCODE: <-1>:<Invalid SQL statement>]
[Location: <Prepare>]
[%msg: < Delimited identifier expected, delimited identifier containing invalid character '.'
found ^ CREATE TABLE "User_BastideRecord.Record">]
ObjectScriptObjectScript
I'm using SQLAlchemy 2.0 and I need to have entities for other tables already created because I will need to make some updates.
Thanks !
Best regards,
Cyril
UPDATE : I just noticed that when I display the metada that I reflect in my engine (when I'm creating the SQLAlchemy engine), I see each tables except the RecordMap table. Is there any solution to get datas from RecordMap ?