[sqlalchemy] Re: AttributeError: 'PropertyLoader' object has no attribute 'strategy'
On Jul 1, 5:53 pm, Michael Bayer [EMAIL PROTECTED] wrote: this means that at least one of the mappers is not fully compiled, but the compiled flag on a mapper which calls upon it is set.This usually implies that the compilation process failed midway, which in all cases would throw an exception. Thanks for the tip, this is exactly what was happening. One of my classes was not mapped correctly. --~--~-~--~~~---~--~~ 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] Display SQL of create table
Hi, Is there a simple way to display the create statements of SA Tables? If I do a my_table.create(), some SQL is created and executed, is there a way to find retrieve this as a string without creating the table? Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 --~--~-~--~~~---~--~~ 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: Display SQL of create table
theres a recipe for this here: http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABLEoutputasastring On Jul 9, 2008, at 8:45 AM, Hermann Himmelbauer wrote: Hi, Is there a simple way to display the create statements of SA Tables? If I do a my_table.create(), some SQL is created and executed, is there a way to find retrieve this as a string without creating the table? Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 --~--~-~--~~~---~--~~ 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] sAsync in complex project
Good day community. I don't know whether it is a good place to asc. I've used sqlalchemy with turbogears and there were no problems. Easy and strateforward. I've got lots of tables with lots of TableClasses where I implement application logic. Now I'm trying to use sqlalchemy with twisted. So I need some magic with threads. sAsync says it is a good place to start. In mine oppinion I see lots of tables separated into separate classes. But when I try to create mine class with table I'm getting errors. sAsync wants to now the whole database structure. but there seems to me no metadata support :( so I'm trying such thing class DUniqaPoliciPlanOplat(AccessBroker): def startup(self): self.table('polici_plan_oplat', Column(u'id_serii', PGInteger(), primary_key=True, nullable=False), Column(u'nom_polica', PGBigInteger(), primary_key=True, nullable=False), Column(u'plan_date', PGDate(), primary_key=True, nullable=False), Column(u'plan_sum', PGFloat(precision=53, asdecimal=False), primary_key=False), Column(u'cod_valuty', PGInteger(), primary_key=False), Column(u'payment_operation', PGBigInteger(), primary_key=False), Column(u'doc_id', PGBigInteger(), primary_key=False), Column(u'is_paid', PGInteger(), primary_key=False), ForeignKeyConstraint([u'cod_valuty'], [u'uniqa.spr_valut.cod_valuty'], name=u'fk_polici_plan_oplat_cod_valuty'), ForeignKeyConstraint([u'nom_polica', u'id_serii'], [u'uniqa.polici_object.nom_polica', u'uniqa.polici_object.id_serii'], name=u'polici_plan_oplat_nom_polica_fkey'), ForeignKeyConstraint([u'doc_id'], [u'documents.document_content.document_id'], name=u'polici_plan_oplat_doc_id_fkey'), ForeignKeyConstraint([u'payment_operation'], [u'accounting.operations.id_operation'], name=u'polici_plan_oplat_payment_operation_fkey'), schema='uniqa' ) but that class could not be created 'cause it doesn't knows what are the different tables. (foreign keys tables)?? creating 1 AccessBroker for the whole database - is a bit unhandy. To be precise - unusable. Cause mine database structure contains over 200 tables with complicated relations. Did anyone knows the solution for this problem? Best regards, Ilya Dyoshin P.S. sorry if this is a wrong place to ask. --~--~-~--~~~---~--~~ 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: Mapped class and c attribute in 0.5
Michael Bayer escreveu: in 0.5, the attributes on classes vs. the columns on Tables are very different beasts now. Got bitten by this too; I'm using MappedClass.c.keys() to serialize all attributes of a class but don't want to write out every field name. Should I use self._sa_class_manager.keys() instead? items = dict() for field in self._sa_class_manager.keys(): items[field] = getattr(self, field) Is there a simpler way, perhaps? Thanks, -- Luis Bruno --~--~-~--~~~---~--~~ 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: integrating SQLAlchemy in a WSGI based framework
Michael Bayer ha scritto: On Jul 8, 2008, at 2:50 PM, Manlio Perillo wrote: Michael Bayer ha scritto: [...] Current integration approaches focus on the scoped_session() construct as home base for the current transaction. Ah, sorry. Sessions are not a problem, since the common pattern for web applications is to create a new session for each transaction (if the user does not like it, then it can use its how logic). well you could have a single session that uses multiple transactions. This is actually more common. Right, thanks. I will add code for storing the session inside the environ dictionary. def scoped_session(environ, **kwargs) where the session factory is stored inside the environ, too. My problem is with contextual connections. the connection-based approach should work as well. whats the problem ? No problems, I was asking because I was not sure. Thanks again Manlio Perillo --~--~-~--~~~---~--~~ 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] Printing the SQL generated by table.create()
Hey all, I've been looking through the documentation and searching google for answers to this, but I can't seem to find a solution. if I set meta.bind.echo=True, I can see the SQL statement that is being generated when I call table.create(). Is there any way I can easily grab this sql statement and store it into a variable (as a string)? I know you can easily print the SQL generated for insert() commands etc, but I can't find an easy way to do this with creates. Sorry if I missed something obvious! Any help would be greatly appreciated. --~--~-~--~~~---~--~~ 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: sAsync in complex project
On Jul 9, 2008, at 11:59 AM, zipito wrote: Good day community. I don't know whether it is a good place to asc. I've used sqlalchemy with turbogears and there were no problems. Easy and strateforward. I've got lots of tables with lots of TableClasses where I implement application logic. Now I'm trying to use sqlalchemy with twisted. So I need some magic with threads. sAsync says it is a good place to start. In mine oppinion I see lots of tables separated into separate classes. But when I try to create mine class with table I'm getting errors. sAsync wants to now the whole database structure. but there seems to me no metadata support :( sAsync is really old, has it been updated for recent SA versions ? (0.3, 0.4, 0.5? ) --~--~-~--~~~---~--~~ 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: Mapped class and c attribute in 0.5
On Jul 9, 2008, at 12:10 PM, Luis Bruno wrote: Michael Bayer escreveu: in 0.5, the attributes on classes vs. the columns on Tables are very different beasts now. Got bitten by this too; I'm using MappedClass.c.keys() to serialize all attributes of a class but don't want to write out every field name. Should I use self._sa_class_manager.keys() instead? items = dict() for field in self._sa_class_manager.keys(): items[field] = getattr(self, field) Is there a simpler way, perhaps? obj.__dict__ is available as always for reading, I'd think thats the easiest way to get at current object state. items = dict([(k, v] for k, v in self.__dict__.iteritems() if not k.startswith('_')]) --~--~-~--~~~---~--~~ 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: Printing the SQL generated by table.create()
Aaron Torres wrote: Hey all, I've been looking through the documentation and searching google for answers to this, but I can't seem to find a solution. if I set meta.bind.echo=True, I can see the SQL statement that is being generated when I call table.create(). Is there any way I can easily grab this sql statement and store it into a variable (as a string)? I know you can easily print the SQL generated for insert() commands etc, but I can't find an easy way to do this with creates. Sorry if I missed something obvious! Any help would be greatly appreciated. There is a recipe in the FAQ: http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABLEoutputasastring Cheers, Jason --~--~-~--~~~---~--~~ 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: Printing the SQL generated by table.create()
On Jul 9, 2008, at 1:09 PM, Aaron Torres wrote: Hey all, I've been looking through the documentation and searching google for answers to this, but I can't seem to find a solution. if I set meta.bind.echo=True, I can see the SQL statement that is being generated when I call table.create(). Is there any way I can easily grab this sql statement and store it into a variable (as a string)? I know you can easily print the SQL generated for insert() commands etc, but I can't find an easy way to do this with creates. Sorry if I missed something obvious! Any help would be greatly appreciated. uh well you could read three messages up today since someone asked the identical question about two hours ago, the answer is still http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABLEoutputasastring . --~--~-~--~~~---~--~~ 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: Printing the SQL generated by table.create()
Ah my apologies, Apparently the search terms I was using to find an answer weren't what I needed! In any case, thanks a lot! This is a real life saver. On Jul 9, 11:13 am, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 9, 2008, at 1:09 PM, Aaron Torres wrote: Hey all, I've been looking through the documentation and searching google for answers to this, but I can't seem to find a solution. if I set meta.bind.echo=True, I can see the SQL statement that is being generated when I call table.create(). Is there any way I can easily grab this sql statement and store it into a variable (as a string)? I know you can easily print the SQL generated for insert() commands etc, but I can't find an easy way to do this with creates. Sorry if I missed something obvious! Any help would be greatly appreciated. uh well you could read three messages up today since someone asked the identical question about two hours ago, the answer is stillhttp://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPT... . --~--~-~--~~~---~--~~ 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] circular model definitions
I'm stumped... Setup: (Problem statement near the bottom) In my Pylons app, I have three separate models: Customer, TPPAnswer, SAQ TPPAnswer is many-to-one Customer SAQ is many-to-one Customer Both have backreferences (so saq.customer and customer.saqs) Currently, I have them defined in customer.py, tpp.py, saq.py. Additionally, I have common.py which is where the metadata object comes from -- all three import everything from common.py In order to have the TPPAnswer many-to-one Customer reference, I import customer_table and Customer so that I can do (w/i tpp.py): from customer import customer_table, Customer ... mapper(Answer, answers_t, properties={ 'customer' :relation(Customer, backref='tpp_answers'), }) I have a similar setup for saq.py. - Problem: in customer.py in the Customer class, I need to reference .tpp_answers and .saqs... but because those references are created in tpp.py and saq.py, they are not known to the Customer class. If I have already imported the tpp model (in my controller), then the Customer object is aware of self.tpp_answers but not self.questionnaires: self.questionnaires AttributeError: 'Customer' object has no attribute 'questionnaires' If I have already imported the saq model, then the Customer object is aware of self.questionnaires but not self.tpp_answers. I can't import both saq and tpp in the controller: self._pre_existing_column = table._columns.get(self.key) AttributeError: 'Column' object has no attribute '_columns' How do I set up my model such that I can import the pieces I need when I need them? So if I call a certain method of the customer object (adjust_grade() for example) it will be able to acquire all the attributes it needs. I don't want to have a massive file with all the relations in them, because most of the time I only need a part of them. For instance, a lot of the things I do with the SAQ model never even interact with the customer -- same with the TPP model. It's the occasional interaction amongst all three of them that's giving me grief. Sorry for such a wordy, confusing explanation. I'm glad to clarify if it helps. - class Customer(object): def adjust_grade(self, *whatchanged): self.tpp_answers self.questionnaires --~--~-~--~~~---~--~~ 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: Mapped class and c attribute in 0.5
Michael Bayer escreveu: Luis Bruno wrote: items = dict() for field in self._sa_class_manager.keys(): items[field] = getattr(self, field) Is there a simpler way, perhaps? obj.__dict__ is available as always for reading, I'd think thats the easiest way to get at current object state. True. I had been using .c.keys() to get database-only attributes because I have some extra methods and attributes . I'll use a '_' prefix as you suggested. Thank you, -- Luis Bruno --~--~-~--~~~---~--~~ 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: circular model definitions
On Jul 9, 2008, at 1:25 PM, Matt Haggard wrote: How do I set up my model such that I can import the pieces I need when I need them? So if I call a certain method of the customer object (adjust_grade() for example) it will be able to acquire all the attributes it needs. I don't want to have a massive file with all the relations in them, because most of the time I only need a part of them. For instance, a lot of the things I do with the SAQ model never even interact with the customer -- same with the TPP model. It's the occasional interaction amongst all three of them that's giving me grief. you answered your own question there...SAQ, TPP and customer can be dependent on a fourth module that defines the interaction between them, which could mean adding properties to mappers, defining the mappers themselves, or just doing the appropriate cross-pollination required for each module. Mappers are designed to be configured completely before use so if there are dependencies present, it does mean that using SAQ implies that TPP and customer would be imported as well. --~--~-~--~~~---~--~~ 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: relation with same class/table on both sides
The manager and direct reports example was just what my project needed. I'm looking forward to upgrading to 0.5 in the future so that I don't have to enter redundant primaryjoin and secondaryjoin on the backref. Thank you Mike! On Jun 28, 1:10 am, Tom Hogarty [EMAIL PROTECTED] wrote: Wow, thank you very much for the detailed example. It looks like just what I need. I look forward to trying it out very soon. -Tom On Jun 27, 6:12 pm, Michael Bayer [EMAIL PROTECTED] wrote: this relation will require you to configure primaryjoin and secondaryjoin (it should be raising an error without them). an example is attached. test.py 1KDownload On Jun 27, 2008, at 5:30 PM, Tom Hogarty wrote: Hello, I have the following scenario where I want the same class/table on both sides of a relation. person table - id - name manager table - person_id - manager_id I define both tables and a Person class, then create a relation in the person mapper like: 'manager' : relation(Person, secondary=managers, backref='direct_reports') When I do this, the 'manager' attribute doesn't show up in Person objects when I query on people. The error I get is: AttributeError: 'Person' object has no attribute 'manager' # query is something like session.query(Person).filter_by(name='Joe').one() Any hints on how I can do this. I have other basic relations working (1-1, 1-M, M-1) but they all have different classes/tables on each end of the relation. Regards, -Tom- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ 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] do not load large binary column but make available on demand
Hello, I have a table that stores binary file data in one column and information about the file (file name, mime type, sha1 sum, etc) in the other columns. Currently when I use the mapped class, it loads the file data (adds to network and memory load). What I would like to do is check the sha1 sum first and then only if needed load the file data. I have been looking into the 'lazy' and 'dynamic' loading options, but they seem to be designed for loading a separate class and not just a single heavy or large property (column) like my file data. Any advice for this situation? I was considering mapping two separate classes, one to the light columns, and another to the heavier data column. I have not mapped separate classes to the same table before though, so any hints on this would be great. Ideally I would like just that data property to lazy-load when accessed, but not sure if there is a 'lazy load this column' setting somewhere. My table is something like: files: - file_name - mime_type - sha1_sum - file_data --~--~-~--~~~---~--~~ 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: do not load large binary column but make available on demand
Sounds like you want deferred loading for the column: http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_deferred --~--~-~--~~~---~--~~ 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: do not load large binary column but make available on demand
Deferred column loading is exactly what I needed, thanks Rick! Coming from a pure SQL background I'm starting to get familiar with all this new ORM and SQLAlchemy terminology. It's worth it though, the code is so much cleaner and more maintainable than stringing together huge complicated SQL queries. On Jul 9, 4:53 pm, Rick Morrison [EMAIL PROTECTED] wrote: Sounds like you want deferred loading for the column: http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_... --~--~-~--~~~---~--~~ 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: do not load large binary column but make available on demand
I started off with using only the SQL-API part of SA myself, but the ORM is way too good to ignore, and I've since converted piles of code over to using the ORM, typically with a 50% loss in lines of code and while getting much better code reuse. The query as a mapper-aware select orientation of the library in the 0.5 version promises the ability to do even more from the ORM side of the street. Anyway, welcome aboard! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---