Re: [sqlalchemy] Getting the entity name, ideally the ORM class in the shard selector?
So anyone else who asks this knows, the following works: A query with just a column: qq = session.query(Configuration.name) Normally I would loop, but in this case, taking just the first column: yy = qq.column_descriptions[0]['expr'] yy.expression.table.name gives: ''configurations” Configuration.__table__.name gives: ''configurations” All good, so we can compare on the underlying table names. Sorry to keep asking questions. If we wanted to do this using the ORM objects, is there a way to get the 'Configuration' object to compare to and not compare the strings with the underlying tables? -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] Getting the entity name, ideally the ORM class in the shard selector?
from that expr, assuming it's a Column, you should be able to say attribute.expression.table, where "attribute" is that InstrumentedAttribute object. If it can be any kind of expression, then you'd need to look into some of the SQL utilities to find tables within the expression. On Apr 22, 2013, at 8:01 PM, Rob Fowler wrote: > If the query does not have a table in it we don't get the tables. > For example, the following simple query gets a list of connection_strings > column from the Connection table: > > aa = session.query(Connection.connection_string) > aa.column_descriptions > > [{'aliased': False, > 'expr': , > 'name': 'connection_string', > 'type': String(length=100)}] > > Exploring into the expr I am not sure how to get the table from that. > > On Tuesday, 23 April 2013 02:32:15 UTC+10, Michael Bayer wrote: > > > use column_descriptions: > http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.column_descriptions > > > > > -- > 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 post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] Getting the entity name, ideally the ORM class in the shard selector?
If the query does not have a table in it we don't get the tables. For example, the following simple query gets a list of connection_strings column from the Connection table: aa = session.query(Connection.connection_string) aa.column_descriptions [{'aliased': False, 'expr': , 'name': 'connection_string', 'type': String(length=100)}] Exploring into the expr I am not sure how to get the table from that. On Tuesday, 23 April 2013 02:32:15 UTC+10, Michael Bayer wrote: > > > > use column_descriptions: > http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.column_descriptions > > > > -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] Getting the entity name, ideally the ORM class in the shard selector?
On Apr 21, 2013, at 10:04 PM, Rob Fowler wrote: > We are using the sharding module included in our application. > > Currently we are selecting shards based on field. This works really well, as > the field that gets hashed to select the shard needs to be migrated to the > other tables that exist only in that shard. > > Now we would like to have some static entities in all databases we would like > to use the table name to indicated that the table is available in all shards. > Ideally we would define a parent class 'unsharded' and derive from that class > for all the unsharded entities. > > I can see the current entities are in _entities, but as that begins with an > underscore I don't think I am meant to be using it. > > What should I use to get the entities from the query? > use column_descriptions: http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.column_descriptions > > ps. Loving sqlalchemy and just started setting up Alembic for our project > (flask, sqlalchemy, postgres). > > -- > 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 post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] Getting the entity name, ideally the ORM class in the shard selector?
We are using the sharding module included in our application. Currently we are selecting shards based on field. This works really well, as the field that gets hashed to select the shard needs to be migrated to the other tables that exist only in that shard. Now we would like to have some static entities in all databases we would like to use the table name to indicated that the table is available in all shards. Ideally we would define a parent class 'unsharded' and derive from that class for all the unsharded entities. I can see the current entities are in _entities, but as that begins with an underscore I don't think I am meant to be using it. What should I use to get the entities from the query? ps. Loving sqlalchemy and just started setting up Alembic for our project (flask, sqlalchemy, postgres). -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.