Using SQLAlchemy and Postgres functions to produce JSON structures from joins
trvrm.github.io
trvrm.github.io
Have people using SQLAlchemy and other ORMs found it helpful to create fake views using the ORM system (i.e. pre-define a commonly used join) so that it can be reused as a simpler black-box unit of code where needed?
http://www.jeffwidman.com/blog/847/using-sqlalchemy-to-creat...
SQLAlchemy's ability to separate out the query API, metadata, data objects, and combine them all via mappers is very powerful. I've been using SQLA for many years, and I still regularly find some functionality that I was never aware of.
Although I'm not working with SQLAlchemy (or Python) I presume it has the power to serialize a TSRANGE into a native Python range (if it has that) as well.
I'm curious if anyone has ever found some way around that, I feel like it isn't possible UNLESS there's some data type than JSON available that I could aggregate with.
If you are able to pull your data from the database and process it in a programming language of your choice, you can write a custom serializer that takes a tsrange and spits out some JSON, e.g. a JSON array with two items [start, end], which you then can pass on to a client that understands your JSON format.
I wish it had a few more capabilities, but since JS doesn't then JSON won't.
> If you are able to pull your data from the database and process it in a programming language of your choice, you can write a custom serializer that takes a tsrange and spits out some JSON, e.g. a JSON array with two items [start, end], which you then can pass on to a client that understands your JSON format.
I can definitely do that. My case though is aggregating and serializing into JSON in postgres and loosing type information due already on the query level.
JSON is a low-level serialization format, on which you often need to build application-specific high-level formats. You can serialize a tsrange into JSON a number of ways, but your deserializer will.need to be aware of the higher-level format you create by your decisions on how to serialize unsupported types as composites of supported types.