[sqlalchemy] Re: Simple view on multiple databases
On Jan 24, 3:52 am, Michael Bayer mike...@zzzcomputing.com wrote: As far as your pick one table with given name X and ignore the others behavior that's some kind of registry logic you'd have to build yourself. Is there an easy way to replicate metadata.tables[]? Inserting my own dict object instead might not promise future compatibility. I need to keep track of new and deleleted table objects. -Christoph -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] autocommit for execute command (was Re: postgresql CREATE SCHEMA statement does not create schema)
I'm belatedly following up to this earlier posting. The problem there was that I wasn't setting autocommit=True in text(). However, I was wondering what I can do if I want to directly write conn.execute(somestuff) conn.close() and have it autocommitted, rather than using text(). The execute() function doesn't appear to have an 'autocommit' option. What can I do to have a autocommit happen in this case? Regards, Faheem. On Wed, 7 Oct 2009 17:37:51 -0400 (EDT), Faheem Mitha fah...@email.unc.edu wrote: Hi, When running this function with postgresql 8.4 and sqla 0.5.5, def test(dbstring): from sqlalchemy import create_engine db = create_engine(dbstring) conn = db.connect() from sqlalchemy.sql import text gq = text( SET search_path TO public; DROP SCHEMA IF EXISTS foo CASCADE; CREATE SCHEMA foo; ) conn.execute(gq) conn.close() the schema foo is not created. However, removing the SET search_path TO public; line makes it work. This is not the case when issuing these commands directly via psql. Any idea what might be going on here? Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~--- -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] dynamic_loader
I am nearly there, at least I think so. class Country_B(Base): __table__ = sa.Table(u'countries_b', metadata, sa.Column(u'id', sa.Integer(), sa.Sequence('countries_b_id'), primary_key=True, nullable=False), sa.Column(u'iso2', sa.String(length=2, convert_unicode=False)), sa.Column(u'iso3', sa.String(length=3, convert_unicode=False)), ) country = sao.dynamic_loader('Country_T', backref=sao.backref('countries_b', lazy='dynamic')) ct = session.query(db.Country_B) for x in ct: try: xy = x.country.filter(db.Country_T.lang_code5==db.getCurrentUserLang()).one() print 'pref: %s' % xy print xy.name except db.sao.exc.NoResultFound: try: print 'def: %s' % x.country.filter(db.Country_T.lang_code5==db.getDefaultUserLang()).one() except db.sao.exc.NoResultFound: print 'no translation found' Now, if I could put this try/except block into the mapper that would be just perfect. Is this possible? If not what else could be done? Werner -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Simple view on multiple databases
On Jan 24, 2010, at 4:14 AM, Christoph Burgmer wrote: On Jan 24, 3:52 am, Michael Bayer mike...@zzzcomputing.com wrote: As far as your pick one table with given name X and ignore the others behavior that's some kind of registry logic you'd have to build yourself. Is there an easy way to replicate metadata.tables[]? Inserting my own dict object instead might not promise future compatibility. I need to keep track of new and deleleted table objects. its a dictionary that uses table.key as keys and the Table object as values. table.key as you know is schema.name or just name. that's pretty much it. The only intricacy with MetaData is that Table objects might reference each other with ForeignKeys. If you don't have any of those, tables can be swapped in and out freely. -Christoph -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] autocommit for execute command (was Re: postgresql CREATE SCHEMA statement does not create schema)
On Jan 24, 2010, at 7:22 AM, Faheem Mitha wrote: I'm belatedly following up to this earlier posting. The problem there was that I wasn't setting autocommit=True in text(). However, I was wondering what I can do if I want to directly write conn.execute(somestuff) conn.close() and have it autocommitted, rather than using text(). The execute() function doesn't appear to have an 'autocommit' option. What can I do to have a autocommit happen in this case? we dont have a per-connection autocommit option, yet.but I have ideas on how to introduce that. but for now if you don't send the option along in the statement, you'd have to do it explicitly, ie. trans = conn.begin(); conn.execute(); trans.commit(). Regards, Faheem. On Wed, 7 Oct 2009 17:37:51 -0400 (EDT), Faheem Mitha fah...@email.unc.edu wrote: Hi, When running this function with postgresql 8.4 and sqla 0.5.5, def test(dbstring): from sqlalchemy import create_engine db = create_engine(dbstring) conn = db.connect() from sqlalchemy.sql import text gq = text( SET search_path TO public; DROP SCHEMA IF EXISTS foo CASCADE; CREATE SCHEMA foo; ) conn.execute(gq) conn.close() the schema foo is not created. However, removing the SET search_path TO public; line makes it work. This is not the case when issuing these commands directly via psql. Any idea what might be going on here? Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~--- -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] dynamic_loader
On Jan 24, 2010, at 8:02 AM, werner wrote: I am nearly there, at least I think so. class Country_B(Base): __table__ = sa.Table(u'countries_b', metadata, sa.Column(u'id', sa.Integer(), sa.Sequence('countries_b_id'), primary_key=True, nullable=False), sa.Column(u'iso2', sa.String(length=2, convert_unicode=False)), sa.Column(u'iso3', sa.String(length=3, convert_unicode=False)), ) country = sao.dynamic_loader('Country_T', backref=sao.backref('countries_b', lazy='dynamic')) ct = session.query(db.Country_B) for x in ct: try: xy = x.country.filter(db.Country_T.lang_code5==db.getCurrentUserLang()).one() print 'pref: %s' % xy print xy.name except db.sao.exc.NoResultFound: try: print 'def: %s' % x.country.filter(db.Country_T.lang_code5==db.getDefaultUserLang()).one() except db.sao.exc.NoResultFound: print 'no translation found' Now, if I could put this try/except block into the mapper that would be just perfect. Is this possible? If not what else could be done? have you considered http://www.sqlalchemy.org/docs/mappers.html#building-query-enabled-properties ? Werner -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: autocommit for execute command (was Re: postgresql CREATE SCHEMA statement does not create schema)
On Sun, 24 Jan 2010 09:27:26 -0500, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 24, 2010, at 7:22 AM, Faheem Mitha wrote: I'm belatedly following up to this earlier posting. The problem there was that I wasn't setting autocommit=True in text(). However, I was wondering what I can do if I want to directly write conn.execute(somestuff) conn.close() and have it autocommitted, rather than using text(). The execute() function doesn't appear to have an 'autocommit' option. What can I do to have a autocommit happen in this case? we dont have a per-connection autocommit option, yet. but I have ideas on how to introduce that. but for now if you don't send the option along in the statement, you'd have to do it explicitly, ie. trans = conn.begin(); conn.execute(); trans.commit(). Thanks for the quick reply. I see. Thanks for the clarification. I can do multiple executes before the final commit, yes? Regards, Faheem. Regards, Faheem. On Wed, 7 Oct 2009 17:37:51 -0400 (EDT), Faheem Mitha fah...@email.unc.edu wrote: Hi, When running this function with postgresql 8.4 and sqla 0.5.5, def test(dbstring): from sqlalchemy import create_engine db = create_engine(dbstring) conn = db.connect() from sqlalchemy.sql import text gq = text( SET search_path TO public; DROP SCHEMA IF EXISTS foo CASCADE; CREATE SCHEMA foo; ) conn.execute(gq) conn.close() the schema foo is not created. However, removing the SET search_path TO public; line makes it work. This is not the case when issuing these commands directly via psql. Any idea what might be going on here? Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~--- -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] dynamic_loader
Michael, On 24/01/2010 15:28, Michael Bayer wrote: ... have you considered http://www.sqlalchemy.org/docs/mappers.html#building-query-enabled-properties ? No - had not found that. Needed a bit to figure it out. I am using declarative and ended up with this. Michael, thanks a lot, I think I am getting there, the following works for me, maybe it is useful for others. class Country_B(Base): __table__ = sa.Table(u'countries_b', metadata, sa.Column(u'id', sa.Integer(), sa.Sequence('countries_b_id'), primary_key=True, nullable=False), sa.Column(u'iso2', sa.String(length=2, convert_unicode=False)), sa.Column(u'iso3', sa.String(length=3, convert_unicode=False)), ) def _get_translation(self): try: x = sao.object_session(self).query(Country_T).with_parent(self).filter(Country_T.lang_code5==getCurrentUserLang) ##print 'def: %s' % x ##print 'def: %s' % getCurrentUserLang() return x.one() except sao.exc.NoResultFound: try: x = sao.object_session(self).query(Country_T).with_parent(self).filter(Country_T.lang_code5==getDefaultUserLang) ##print 'def: %s' % x ##print 'def: %s' % getDefaultUserLang() return x.one() except sao.exc.NoResultFound: return 'no translation found' country_t = sao.relation('Country_T', backref='country_b') country = property(_get_translation) Next thing is to make _get_translation reusable for different tables. Werner -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Simple view on multiple databases
On Jan 24, 3:19 pm, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 24, 2010, at 4:14 AM, Christoph Burgmer wrote: On Jan 24, 3:52 am, Michael Bayer mike...@zzzcomputing.com wrote: As far as your pick one table with given name X and ignore the others behavior that's some kind of registry logic you'd have to build yourself. Is there an easy way to replicate metadata.tables[]? Inserting my own dict object instead might not promise future compatibility. I need to keep track of new and deleleted table objects. its a dictionary that uses table.key as keys and the Table object as values. table.key as you know is schema.name or just name. that's pretty much it. The only intricacy with MetaData is that Table objects might reference each other with ForeignKeys. If you don't have any of those, tables can be swapped in and out freely. I have implemented a dictionary that does lazy lookup of Table objects using their simple names and is used now instead of the one provided by MetaData. As data is relatively stable/should be modified in a way stipulated by the library this currently seems enough logic for my use case. A nice gimmick for the future though would be a trigger for syncing updates with the MetaData class. If anybody is interested, source code went into: http://code.google.com/p/cjklib/source/browse/trunk/cjklib/dbconnector.py?spec=svn245r=245 -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Is it possible to narrow down the generated query in SQLAlchemy if it was created via query_property?
I have a question about SQLAlchemy. If I have added a query_property [1] field in my SQLAlchemy Table class, is it possible to narrow down the SELECTed fields? Here is what I mean. Suppose my class Comments has this: class Comments: query = Session.query_property() ... Then if I do the following: print Session.query(Comment) Then SQLAlchemy generates the following query which includes ALL the columns in my comments table: SELECT comments.comment_id AS comments_comment_id, comments.commentAS comments_comment ... more columns ... FROM comments But I want to narrow down this query and select only (let's say) the comment field as in the following construct: print Session.query(Comment.comment) SELECT comments.comment AS comments_comment FROM comments Is it possible to do this via Comment.query construct? I tried the following but it didn't work: print Comment.query(Comment.comment) Traceback (most recent call last): File stdin, line 1, in module TypeError: 'Query' object is not callable Please help me with an advice. Thanks, Boda Cydo. [1] http://www.sqlalchemy.org/docs/reference/orm/sessions.html#sqlalchemy.orm.scoping.ScopedSession.query_property -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Is it possible to narrow down the generated query in SQLAlchemy if it was created via query_property?
Let me know if the question is not clearly stated. I'll update it with more details. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: SQL Server 2008 geography type
Thank you Michael, that really helped a lot. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.