Question
· Jan 2

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())

 

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]

 

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))

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">]

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 ?

Product version: IRIS 2023.1
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2023.1.1 (Build 380U) Fri Jul 7 2023 23:53:46 EDT [Health:5.1.0-1.m1]
Discussion (0)1
Log in or sign up to continue