[spyne] Postgresql schemas

Красильников Юрий Юрьевич skaradub at yandex.ru
Wed Mar 1 06:25:03 UTC 2017


Hello there!

Thanx, Burak! It helped, I found at sqlalchemy Metadata Param "schema" and used it  like this:

class TableModel2(ComplexModelBase):
    __metaclass__ = ComplexModelMeta
    __metadata__ = MetaData(bind=db, schema='public')

class TableModel3(ComplexModelBase):
    __metaclass__ = ComplexModelMeta
    __metadata__ = MetaData(bind=db, schema='mon_ts_test')

but there is nuance: if you add schema to super class, you can't define several tables with the same __tablename__, but sometimes it is useful and used in my project. so I made it like this at the end:

# base class, used before serveral schemas appeared, I added schema to it to be consistent
class TableModel(ComplexModelBase):
    __metaclass__ = ComplexModelMeta
    __metadata__ = MetaData(bind=db, schema='public')

# same as base class, but used only for tables, that appear in model more than once
class TableModel2(ComplexModelBase):
    __metaclass__ = ComplexModelMeta
    __metadata__ = MetaData(bind=db, schema='public')

# new schema that is used for new functionality
class TableModel3(ComplexModelBase):
    __metaclass__ = ComplexModelMeta
    __metadata__ = MetaData(bind=db, schema='mon_ts_test')

Regards, 
Yury

28.02.2017, 17:43, "Burak Arslan" <burak.arslan at arskom.com.tr>:
> Hey there,
>
> On 02/28/17 17:37, Красильников Юрий Юрьевич wrote:
>>  Good day everyone!
>>
>>  Our small project ate another one =) and we need to merge masterdata and the same time separate business logic in different schemas. SO:
>>
>>  Are there any params in ComplexModelBase to connect to exact schema in Postgesql? Or I'll have to switch to Sqlalchemy this time?
>
> Spyne already integrates with SqlAlchemy. However, you need to inherit
> from TableModel instead of ComplexModel and specify a table name.
>
> Would what's here => http://spyne.io/#s=sql&ser=SqlOtm&show=Schema not
> help you? If not, can you show me some code so I can see the issue?
>
> Best regards,
> Burak
>
>>  Thanx in Advance!
>>
>>  Regards,
>>  Yury
>>  _______________________________________________
>>  Spyne community mailing list
>>  people at spyne.io
>>  http://lists.spyne.io/listinfo/people


More information about the people mailing list