[sqlalchemy] Obtaining primitive columns from a select
Hi all, I'd like to have a generic function that executes a given SQL query filtering it with conditions passed as keyword args, but I do not find a clean way to refer to the primitive columns (on the underlying table) instead of those already bound to the select. Given a simple select:: query = sometable.select() and a dictionary:: args = { 'somecolname': 'avalue', 'othercolname': 1 } I tried to implement a simple function:: def apply_filters(query, args): ... for colname in args: ... query = query.where(XXX(colname) == args[colname]) ... return query I first tried using query.columns[colname] in place of the XXX() stub, but that does not do the job, because it brings in a subselect. Of course it works when I refer to the table columns, but how can I reach them having just the query on the table? I tried inspecting the query, that carries a _raw_columns, or _froms, but it does not seem a clean approach. What am I missing? Thanks in advance for any hint, ciao, lele. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: M2M relationship
Hi Michael, create a file called something like globals.py, and in all other modules that use SQLAlchemy, say import globals. A primer on modules, packages and such is at http://www.python.org/doc/tut/node8.html Excellent! This seems to have done the job, I am now successfully saving and pulling these objects from the database, very cool! Thank you again. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Filter by optional attributes.
Good morning guys, I'm looking for a way in which I can query my database for records which meet multiple, optional arguments. I'm looking to encapsulate access to this using a service layer, I want to create a method like this: def get_foos(self, foo_id=, foo_firstname=, foo_lastname=): foos = session.query(Foo).filter_by(foo_id=foo_id, foo_firstname=foo_firstname, foo_lastname=foo_lastname) return foos Now, the thing I'm struggling with is how to make all those attributes optional. Because at the moment I call that method like so: get_foos(foo_id=2) I get no results returned because SQLAlchemy is looking for records that not only have an id of 2 but also have a first and last name which is an empty string. What I would ideally like to do is only have it filter by the arguments for getfoos() which are not empty strings. This would allow me to build a more reusable query method. Is this possible? And how would one achieve it? Cheers, Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Filter by optional attributes.
use keywordargs as dictionary, i.e. ...query.filter( **kwargs) where the kwargs are a dict made by u containing only the required fields. e.g. kwargs={} if foo_id: kwargs['fooid']=fooid ... u can make it more generic (but more dangerous) by passing any kwargs coming to your func straight down to filter(): def myfunc( self, whateverotherstuff, **filterkwargs): .. query.filter( **filterkwargs) or some combination inbetween. dont forget that filter( ...) does AND of the criterias. svil On Tuesday 15 July 2008 14:55:01 Heston James - Cold Beans wrote: Good morning guys, I'm looking for a way in which I can query my database for records which meet multiple, optional arguments. I'm looking to encapsulate access to this using a service layer, I want to create a method like this: def get_foos(self, foo_id=, foo_firstname=, foo_lastname=): foos = session.query(Foo).filter_by(foo_id=foo_id, foo_firstname=foo_firstname, foo_lastname=foo_lastname) return foos Now, the thing I'm struggling with is how to make all those attributes optional. Because at the moment I call that method like so: get_foos(foo_id=2) I get no results returned because SQLAlchemy is looking for records that not only have an id of 2 but also have a first and last name which is an empty string. What I would ideally like to do is only have it filter by the arguments for getfoos() which are not empty strings. This would allow me to build a more reusable query method. Is this possible? And how would one achieve it? Cheers, Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Filter by optional attributes.
Hi Svil: use keywordargs as dictionary, i.e. ...query.filter( **kwargs) where the kwargs are a dict made by u containing only the required fields. e.g. kwargs={} if foo_id: kwargs['fooid']=fooid That sounds like a fair enough solution to me, seems safer than the more generic version. Thanks for the tip mate, sounds really great. I'll play around with that concept. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Filter by optional attributes.
Hello Again Svil: That sounds like a fair enough solution to me, seems safer than the more generic version. Thanks for the tip mate, sounds really great. I'll play around with that concept. Heston I've tested this little concept and it works really nicely :-D thanks. One quick question I'd like to pick your brain on. With filter(), is that filter applied at the SQL level? Or are _all_ records returned from the database and then SQLAlchemy applies the filter? I'm just trying to get an idea of performance when we have many records, I'd hate to be pulling them _all_ from the database with each query. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Filter by optional attributes.
Hi, pass an echo=True to the create_engine() (or whereever else u could pass that) and u'll see the sql. Ok, I see! Perfect! I've just configured logging on this so I can keep track, looks excellent. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Injecting business objects into constructor
Afternoon Guys, In my classic non-orm based applications I would usually inject other business object instances into my classes for such things as logging, emailing and all manner of other things. For instance: class foo: def __init__(self, logger, email_service, foo_id=, foo_firstname=): self.logger = logger self.email_service = email_service self.foo_id = foo_id self.foo_firstname = foo_firstname Now that I'm using the ORM I ask the ORM for these objects, however, it obviously just hands me back an instance with all its properties loaded from the database, what is essentially a glorified dict or 'dumb' object. How would you go about getting these business objects into the objects returned by the ORM? Would you have your service layer set them before returning the object? Or can we somehow configure the ORM to do it for us? Thanks guys, I'm really enjoying this. Heston --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: unexpected behavior with relation and filter_by
On Jul 14, 2008, at 7:19 PM, Jon wrote: I've encountered some weird stuff. I'm probably doing it wrong, but I don't understand *why*. The following code: s = Session() # returns all accounts, the .licenses param # not taken into consideration accts = s.query(Account).filter(Account.licenses==[]) print accts print accts = s.query(Account).filter(Account.licenses.any()) print accts print # returns the correct list of accounts. accts = s.query(Account).filter(Account.licenses==None) print accts print print accts[0].licenses # prints [] not None. Comparison to lists is currently taken to mean return objects whos collection contains these elements, i.e. its like a mass Account.licenses.contains() operator. So if you compare to an empty list that would return all parent elements. Comparison to None returns items using a NOT EXISTS clause, i.e. parent items with no child items. any() returns items where any of them meet the given criterion -since the criteiron is blank here, all child items match. any() is the best operator to use when asking for parents with no child items, using ~Account.licenses.any() (I think theres a tutorial example to this effect). Once loaded, all collection-based attributes default to the empty collection if no elements are present, which is by default a list. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Bug in 0.4.6/0.5 ?
Hello list, I recently installed 0.4.6 to check the news, and with horror I saw this dump: Traceback (most recent call last): File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 85, in onCheckUtente self.checkUtente(self.inputUser.GetValue().lower()) File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 64, in checkUtente user = mapperFunctions.getUtente(user) File /media/userdata/stefano/Documenti/projects/Tosi/erp/dyemagic2/mapperFunctions.py, line 19, in getUtente rep = mappers.Reparto.query.first() #Per inizializzare la sessione File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/scoping.py, line 144, in __getattr__ return getattr(self.context.registry().query(class_), key) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 97, in __init__ self.__setup_aliasizers(self._entities) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 111, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity, ent.entity_name) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 398, in _entity_info mapper = class_mapper(entity, entity_name, compile) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 488, in class_mapper mapper = mapper.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 368, in compile mapper.__initialize_properties() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 389, in __initialize_properties prop.init(key, self) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 378, in init self.do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 514, in do_init self._post_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 750, in _post_init super(PropertyLoader, self).do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 548, in do_init self.strategy = self.__init_strategy(self.strategy_class) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 537, in __init_strategy strategy.init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/strategies.py, line 339, in init self.logger.info(%s lazy loading clause %s % (self, self.__lazywhere)) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1155, in __str__ return unicode(self.compile()).encode('ascii', 'backslashreplace') File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1151, in compile compiler.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 175, in compile self.string = self.process(self.statement) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 377, in visit_binary return self.process(binary.left) + + op + + self.process(binary.right) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 227, in visit_grouping return ( + self.process(grouping.element) + ) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 507, in visit_select for co in select.inner_columns File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 463, in label_select_column return column.label(column.anon_label) AttributeError: '_BindParamClause' object has no attribute 'anon_label' After some helpless googling for version upgrade errors, I read the code and I added _BindParamClause in function label_select_column: elif not isinstance(column, (sql._UnaryExpression, sql._TextClause)) and (not
[sqlalchemy] Bug in 0.4.6/0.5 ?
I recently installed 0.4.6 to check the news, and with horror I saw this dump: Traceback (most recent call last): File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 85, in onCheckUtente self.checkUtente(self.inputUser.GetValue().lower()) File /media/userdata/stefano/Documenti/projects/Tosi/erp/login.py, line 64, in checkUtente user = mapperFunctions.getUtente(user) File /media/userdata/stefano/Documenti/projects/Tosi/erp/dyemagic2/mapperFunctions.py, line 19, in getUtente rep = mappers.Reparto.query.first() #Per inizializzare la sessione File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/scoping.py, line 144, in __getattr__ return getattr(self.context.registry().query(class_), key) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 97, in __init__ self.__setup_aliasizers(self._entities) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/query.py, line 111, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity, ent.entity_name) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 398, in _entity_info mapper = class_mapper(entity, entity_name, compile) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/util.py, line 488, in class_mapper mapper = mapper.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 368, in compile mapper.__initialize_properties() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/mapper.py, line 389, in __initialize_properties prop.init(key, self) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 378, in init self.do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 514, in do_init self._post_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/properties.py, line 750, in _post_init super(PropertyLoader, self).do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 548, in do_init self.strategy = self.__init_strategy(self.strategy_class) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/interfaces.py, line 537, in __init_strategy strategy.init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/orm/strategies.py, line 339, in init self.logger.info(%s lazy loading clause %s % (self, self.__lazywhere)) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1155, in __str__ return unicode(self.compile()).encode('ascii', 'backslashreplace') File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/expression.py, line 1151, in compile compiler.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 175, in compile self.string = self.process(self.statement) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 377, in visit_binary return self.process(binary.left) + + op + + self.process(binary.right) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 227, in visit_grouping return ( + self.process(grouping.element) + ) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 507, in visit_select for co in select.inner_columns File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2-py2.5.egg/sqlalchemy/sql/compiler.py, line 463, in label_select_column return column.label(column.anon_label) AttributeError: '_BindParamClause' object has no attribute 'anon_label' After some helpless googling for version upgrade errors, I read the code and I added _BindParamClause in function label_select_column: elif not isinstance(column, (sql._UnaryExpression, sql._TextClause)) and (not hasattr(column,
[sqlalchemy] Re: Bug in 0.4.6/0.5 ?
Did you call something like select([literal('foo')]) ?If you use straight Python literals in the columns clause (i.e. select(['foo'])), they will be rendered directly, which is probably what you want here. This is fixed in r4933 / r4934 0.5 trunk/ 0.4 branch. On Jul 15, 2008, at 10:52 AM, Stefano Bartaletti wrote: I recently installed 0.4.6 to check the news, and with horror I saw this dump: Traceback (most recent call last): File /media/userdata/stefano/Documenti/projects/Tosi/erp/ login.py, line 85, in onCheckUtente self.checkUtente(self.inputUser.GetValue().lower()) File /media/userdata/stefano/Documenti/projects/Tosi/erp/ login.py, line 64, in checkUtente user = mapperFunctions.getUtente(user) File /media/userdata/stefano/Documenti/projects/Tosi/erp/dyemagic2/ mapperFunctions.py, line 19, in getUtente rep = mappers.Reparto.query.first() #Per inizializzare la sessione File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/scoping.py, line 144, in __getattr__ return getattr(self.context.registry().query(class_), key) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/query.py, line 97, in __init__ self.__setup_aliasizers(self._entities) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/query.py, line 111, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity, ent.entity_name) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/util.py, line 398, in _entity_info mapper = class_mapper(entity, entity_name, compile) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/util.py, line 488, in class_mapper mapper = mapper.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/mapper.py, line 368, in compile mapper.__initialize_properties() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/mapper.py, line 389, in __initialize_properties prop.init(key, self) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/interfaces.py, line 378, in init self.do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/properties.py, line 514, in do_init self._post_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/properties.py, line 750, in _post_init super(PropertyLoader, self).do_init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/interfaces.py, line 548, in do_init self.strategy = self.__init_strategy(self.strategy_class) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/interfaces.py, line 537, in __init_strategy strategy.init() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/orm/strategies.py, line 339, in init self.logger.info(%s lazy loading clause %s % (self, self.__lazywhere)) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/expression.py, line 1155, in __str__ return unicode(self.compile()).encode('ascii', 'backslashreplace') File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/expression.py, line 1151, in compile compiler.compile() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 175, in compile self.string = self.process(self.statement) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 377, in visit_binary return self.process(binary.left) + + op + + self.process(binary.right) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 227, in visit_grouping return ( + self.process(grouping.element) + ) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 183, in process return meth(obj, **kwargs) File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 507, in visit_select for co in select.inner_columns File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta2- py2.5.egg/sqlalchemy/sql/compiler.py, line 463, in
[sqlalchemy] Re: session.dirty but not session.is_modified....
popping from dirty() wont change anything since its a set thats generated each time it's called. this is from the doc for dirty(): Note that this 'dirty' calculation is 'optimistic'; most attribute-setting or collection modification operations will mark an instance as 'dirty' and place it in this set, even if there is no net change to the attribute's value. At flush time, the value of each attribute is compared to its previously saved value, and if there's no net change, no SQL operation will occur (this is a more expensive operation so it's only done at flush time). To check if an instance has actionable net changes to its attributes, use the is_modified() method. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: srid autodiscovery mechanism
Michael Bayer wrote: On Jul 13, 2008, at 5:42 PM, Eric Lemoine wrote: So far, so good; user can do: wifi_table = Table('wifi', metadata, Column('the_geom', Geometry(4326)), autoload=True) But ultimately I'd like that my users can do: wifi_table = Table('wifi', metadata, autoload=True) I tried this: from sqlalchemy.databases import postgres postgres.ischema_names['geometry'] = Geometry This is ok, but during reflection, when SQLA creates Geometry objects, it obviously passes no srid argument to the Geometry constructor, so the Geometry objects all end up with the srid property set to -1. The proper srid value to pass to the Geometry constructor is actually in a PostGIS table (geometry_columns). So if a geometry column is discovered, the table's srid value could be read from that table and passed to the Geometry constructor. I thought about doing something like that: from sqlalchemy.databases import postgres def geometry_factory(): // go read srid associated with table from geometry_columns srid = return Geometry(srid) postgres.ischema_names['geometry'] = geometry_factory but geometry_factory doesn't have any connection object to go read the srid value. My question is simple: do you see solutions to my problem? like before with asdecimal=False, we dont have a standard API for the ischema_names dict and again here is a place where you're looking for one. Such an API might look like: def create_postgis_type(table, connection): srid = connection.execute(select whatever you need to figure out SRID value).scalar() return Geometry(srid=srid) engine = create_engine('postgres://...', type_reflectors={ 'numeric':PGFloat, 'PostGIS':create_postgis_type }) where reflecttable() distinguishes between a TypeEngine class and a plain callable, which is assumed to implement a particular API. But thats just a guess. I wouldn't implement such an API casually since while its very easy to add little features like this, its much harder to change them or take them away after you've observed they're a bad idea or were not well thought out (additionally this one's a pretty big job to implement across every dialect). Any opinions from Jason/ Rick/other ? Would be pretty useful. Would the mapping have to go deeper, and control the resolution of (e.g.) String - PGString across the board for the dialect? The reflection factories would probably want some *args and **kw to pass along column/type metadata snarfed up in the first phase of reflection. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Injecting business objects into constructor
I'm not sure where this is going with the 0.5 version, but I believe that MappedClass.__int__ is still not called when objects are loaded from the DB. If that's the case, and there isn't some alternate that SA provides like MappedClass.__onload__, You can look into Mapper Extensions to provide this. Check out the 'create_instance' method. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Load capabilities with default pool_size and max_overflow
Hello SQLAlchemists, What is (or what do you think is) the load that SQLAlchemy can handle with the default engine options of pool_size=5 and max_overflow=10? The application I'm working on has the potential for bursts of thousands of requests in a few seconds, so I am concerned about load. Is it appropriate to increase these values to some arbitrary number? I see that you can set max_overflow to -1 so that it creates as many connections as needed, but do you think that would be necessary (or bad practice)? Thanks for any advice about this, I'm trying to understand the nature of connections and the QueuePool implementation to avoid load problems when we go live. Any simple way to script exceeding the QueuePool limit quickly for load testing? Thanks for the help, much appreciated. And also, I've wanted to throw out a huge thank you to the developers ... on top of SQLAlchemy being extremely robust and powerful, the SQLAlchemy documentation is impeccable. Better than most all other open source software ... *awesome* ... so, thank you. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Load capabilities with default pool_size and max_overflow
--On 15. Juli 2008 22:32:35 -0700 Fotinakis [EMAIL PROTECTED] wrote: Hello SQLAlchemists, What is (or what do you think is) the load that SQLAlchemy can handle with the default engine options of pool_size=5 and max_overflow=10? The application I'm working on has the potential for bursts of thousands of requests in a few seconds, so I am concerned about load. Default settings are called that way because they make sense to possibly 80% of all use-cases. Don't expect that a high-traffic environment works without tuning. So the answer is basically: unlikely. Is it appropriate to increase these values to some arbitrary number? Those parameters are exposed as part of the API for performing such a tuning?! -aj pgpjvt2cUDjxr.pgp Description: PGP signature