Hi there, we are considering using SQLAlchemy, specifically the Core part, for our project. I'm guessing we won't need ORM, but we keep an open mind.
One of the things we would like to do is this: after connecting to a database (read-only), we would like to present to the end-user a view of a given table (or actually a join of tables) as a "view". This won't necessarily be an actual database view/table, also given that we don't want to modify the database.
For example, say there are two tables (forgive the made-up syntax).
Country(countryCode: string(2), population: Integer, gdp: Float)
City(cityCode: string(3), countryCode: ForeignKey string(2), population: Integer, altitude: Integer)
Say I join these and I want to present this schema to the user:
SimplifiedCity(fullCode: string(6), cityPopulation: Integer)
where fullCode is the concatenation of Country.countryCode || '.' || City.cityCode, e.g. 'GB.LON'
That way, the users will be able to query SimplifiedCity, with the unnecessary details hidden from them, like so:
query =
select([simplifiedCity.
c.cityPopulation]).where(simplifiedCity.
c.fullCode = 'GB.LON')
Is this possible? I noticed the existence of sqlalchemy-views, but I'm guessing that would have to be done within a transaction that we then roll back, which doesn't sound great. Also, I wonder if there are better, more idiomatic ways.
Thanks!