xnuinside / omymodels

O!My Models (omymodels) is a library to generate Pydantic, Dataclasses, GinoORM Models, SqlAlchemy ORM, SqlAlchemy Core Table, Models from SQL DDL. And convert one models to another.
MIT License
178 stars 20 forks source link

Option to have different schemas in separate files, with separate Base #40

Open leppikallio opened 2 years ago

leppikallio commented 2 years ago

It would be really nice and helpful if it were possible to have SQLAlchemy model "split" in to separate, schema specific, files with a schema specific Base.

As an example, if a DDL had something like

CREATE SCHEMA schema1;
CREATE SCHEMA schema2;
CREATE TABLE schema1.table1 (
...
);
CREATE TABLE schema2.table2 (
...
);

the -m sqlalchemy in combination with a new option would produce two model files,

schema1.py schema2.py

with

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base

Schema1Base = declarative_base()
class Table1(Schema1Base):

    __tablename__ = "table1"
    __table_args__ = {"schema": "schema1"}

and

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base

Schema2Base = declarative_base()
class Table2(Schema2Base):

    __tablename__ = "table2"
    __table_args__ = {"schema": "schema2"}

respectively. This would be amazingly helpful & useful feature as it would make it possible to really separate the schemas.

xnuinside commented 2 years ago

@leppikallio hi! thanks for reporting the issue. I can implement it on weekend

leppikallio commented 2 years ago

To be clear, this is not that much an issue, rather an extension to already brilliant tool. But it would be amazing if this would be possible.

peterdudfield commented 1 year ago

Did this get done? I'm happy to try and give it a go if you want

xnuinside commented 1 year ago

@peterdudfield nope, I didn't start work on it, you can take care about it, if you want