Re: [sqlalchemy] "Virtual models" for JSONB data?
OK, thanks a lot anyway! I was just wondering if there was already some solution I could reuse. Cheers, Pedro On 03.07.20 17:26, Mike Bayer wrote: > I suppose. that seems really complicated. When we use the ORM, we're > defining our domain model in terms of objects, then we define a > persistence layer in terms of relational tables. The Declarative > approach is a compromise between the more strict mapper() approach, > which looks like mapper(class, Table) and the need to have the > declaration of classes and their data members be succinct and > localized. however if you are defining an alternative form of > persistence , then all of the ORM capabilities go away, they'd have to > be reimplemented in terms of that new persistence model. > > short answer, things like relationships and all that you would need to > re-implement in some other way that works in terms of json records. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/e89791b0-5b63-cb40-1c60-3ccb94c5f51b%40cern.ch. signature.asc Description: OpenPGP digital signature
[sqlalchemy] "Virtual models" for JSONB data?
Hi, I was wondering if there's some way to create some sort of a "virtual" model which is not based on an actual table? Use case: I have a model (e.g. `Room`) which contains a `data` JSONB attribute/column which is supposed to store plugin-specific data. I would like plugin code to be able to create a "virtual" model which references `Room` 1-to-1 and injects a `plugin_data` backref into it. That means I would be able to do `room.plugin_data.user`, for instance, which would use `room.data['user_id']` to fetch a `User` object. Right now, our plugins do this by means of an additional table. E.g., in this case we would have `PluginRoom`, which would store `user_id` and have a 1-to-1 relationship with `Room`, with a backref. I was wondering if there's some way we can have a similar pattern based on unstructured JSONB data. Cheers, Pedro -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/5581edb1-3cbe-2179-f925-dbeaaa7523b8%40cern.ch. signature.asc Description: OpenPGP digital signature