[sqlalchemy] Re: query.filter and entity_name
Thank you Michael, I will use subclassing instead. A mention of this technique in the documentation (in the Multiple Mappers for One Class) would be great, as it is the place I was looking for a solution to my problem when I found entity_name. Best regards, Christophe 2008/7/7 Michael Bayer [EMAIL PROTECTED]: It's currently preferred if you didn't use entity_name since it works quite poorly and even worse in 0.5, and we'd like to remove it - it has built-in undefined behavior in that its not determined which set of attribute instrumentation gets applied to the class. This feature is an artifact of Hibernate which we copied at some point but doesn't apply well to Python where subclassing does not place a significant structural burden on code (and multiple inheritance makes it even less burdensome). Mapping to individual subclases is much more straightforward - its the difference between your instance which is of class A plus magic entity name attribue B, versus, your instance is of class B subclassing A. The object has state which represents the entity_name in either case. We haven't yet removed entity_name from 0.5 because I'm waiting for someone to have a truly compelling argument for it. On Jul 7, 2008, at 6:45 AM, Christophe de VIENNE wrote: Hi, I'm having trouble using entity_name. I have two mappers for the same class, one of them having an entity_name=legacy. If I do a query with the legacy mapper, I cannot figure how to filter on properties. Ex: session.query(MyClass, entity_name='legacy').filter( MyClass.arelationprop.has( criterions )) In this case, the table from the default mapper is always getting in the way. I think I am not using properly the alternate mapper, but cannot find any example. Thanks a lot, Christophe --~--~-~--~~~---~--~~ 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: Connecting to MySQL
On Thu, Jul 10, 2008 at 8:20 AM, Heston James [EMAIL PROTECTED] wrote: Good afternoon guys, I'm brand new to SQLAlchemy as of about 2 minutes ago, I have a couple of starter questions that I wanted to run past you, with any luck they'll be simple for you to answer. After looking through the quick tutorial, which showed me just about all I need to know http://www.sqlalchemy.org/docs/05/ormtutorial.html it talks about connecting to an in memory sqllite database using a connection string like so: create_engine('sqlite:///:memory:', echo=True) Here is a list of possible connection strings. Its more towords turbogears way but it will get you started. http://lucasmanual.com/mywiki/TurboGears#head-8457721059b18a5f2264f8484082deb5b294d27a Here is sqlalchemy: http://www.sqlalchemy.org/docs/05/dbengine.html#dbengine_establishing (ps. could you guys add the connection strings to you docs I have listed them in the top link. I've mentioned this before but I guess it wasn't added to you official docs back then.) And you should read over: http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html How would I connect to a local MySQL database? The database I'm working with is already designed and built, which leads me onto my next question: In the tutorial documentation it talks about 'Defining and Creating a Table'. Is this something which need only be done when we're working with an in-memory database? or do I have to define my database schema even if its a pre-existing mysql database? or does SQLAlchemy introspect it or something? You auto load the existing database. My thrid and final question is about the persistance of composed objects. If I save an object using sql alchamy, I see it also saves the objects children. Is this done in a transaction by default? if the save process on one of its children fails will it all be rolled back? or is this something I have to specify seperatly? Thanks guys, once I know those little items I'm sure I'll be able to get up and running pretty swiftly. Cheers, Lucas --~--~-~--~~~---~--~~ 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: Connecting to MySQL
Session.add is a version 0.5 method, you're maybe running 0.4.6? In the 0.4.x series, it's going to be: Session.save() for objects that are to be newly added to the session Session.update() for objects that are already in the session, or Session.save_or_update() to have the library figure it out as it does for Session.add in v0.5.x --~--~-~--~~~---~--~~ 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
zipito wrote: Good day community. I don't know whether it is a good place to asc. Probably as good as any. You might try on the Twisted mailing list (or newsgroup gmane.comp.python.twisted) as well. Happy hunting, -- Don Dwiggins Advanced Publishing Technology --~--~-~--~~~---~--~~ 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: Connecting to MySQL
Session.add is a version 0.5 method, you're maybe running 0.4.6? In the 0.4.x series, it's going to be: Session.save() for objects that are to be newly added to the session Session.update() for objects that are already in the session, or Session.save_or_update() to have the library figure it out as it does for Session.add in v0.5.x Hi Rick, That's exactly what the problem was :-) Is there any reason I should avoid using 0.5? I'm running python 2.4 at the moment, are they compatible? Next quick question: I have a habbit of using 'created' and 'modified' columns on my tables, is there any way in which I can have the ORM update the dates for me when creating and modifying rows? 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: Connecting to MySQL
That's exactly what the problem was :-) Is there any reason I should avoid using 0.5? I'm running python 2.4 at the moment, are they compatible? 0.5 is still in beta, and I don't have much experience with it myself, but if were just starting out, I would probably be using that, otherwise you'll need to migrate later; it's easier to just start out with the new API. Next quick question: I have a habbit of using 'created' and 'modified' columns on my tables, is there any way in which I can have the ORM update the dates for me when creating and modifying rows? Yes, check out mapper extensions in the docs, you're going to want after_insert and after_update extensions. --~--~-~--~~~---~--~~ 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: Connecting to MySQL
Lukasz Szybalski wrote: On Thu, Jul 10, 2008 at 11:26 AM, Heston James - Cold Beans [EMAIL PROTECTED] wrote: Session.add is a version 0.5 method, you're maybe running 0.4.6? In the 0.4.x series, it's going to be: Session.save() for objects that are to be newly added to the session Session.update() for objects that are already in the session, or Session.save_or_update() to have the library figure it out as it does for Session.add in v0.5.x Hi Rick, That's exactly what the problem was :-) Is there any reason I should avoid using 0.5? I'm running python 2.4 at the moment, are they compatible? Next quick question: I have a habbit of using 'created' and 'modified' columns on my tables, is there any way in which I can have the ORM update the dates for me when creating and modifying rows? From the link I sent you previously: sqlalchemy.Column('CreatedDate', sqlalchemy.Date, default=datetime.now().date()), sqlalchemy.Column('CreatedTime', sqlalchemy.Time, default=datetime.now().time()) Not so much. That'll stamp every inserted row with the same time- whatever time it was when python evaluated the Table definition. Here's a cross-db way to get timestamps: from sqlalchemy import Table, Column, DateTime, func Table('abc', metadata, ... Column('created', DateTime, default=func.now()), Column('updated', DateTime, onupdate=func.now())) You can set both default= and onupdate= on the same Column if you want 'updated' to be non-NULL on insert. --~--~-~--~~~---~--~~ 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] propLoader comparisons
hi i got that the only allowed non-relational expressions over a reference (PropLoader) are: someklas.propname == instance and that would be translated into someklas.table.c.primarykey == instance.primarykey is there a way to apply same thing for =/= i.e. le/ge? (without resorting to column-level) somehow add le/ge to PropLoader.Comparator? its about some sort-of audit-log, which dbid is used as a revision-number for the referring classes. i.e. i want to get objects with revisions before someRevisionInstance, comparing Revision.db_id. ciao svilen --~--~-~--~~~---~--~~ 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: propLoader comparisons
before mappers are compiled, you pull out comparator_factory from your relation(), and set it to be some class of your own which subclasses PropComparator and implements __le__()/__gt__() . It wouldn't be hard to add comparator_factory as a keyword argument to relation() either. On Jul 10, 2008, at 3:02 PM, [EMAIL PROTECTED] wrote: hi i got that the only allowed non-relational expressions over a reference (PropLoader) are: someklas.propname == instance and that would be translated into someklas.table.c.primarykey == instance.primarykey is there a way to apply same thing for =/= i.e. le/ge? (without resorting to column-level) somehow add le/ge to PropLoader.Comparator? its about some sort-of audit-log, which dbid is used as a revision-number for the referring classes. i.e. i want to get objects with revisions before someRevisionInstance, comparing Revision.db_id. ciao svilen --~--~-~--~~~---~--~~ 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] mysql innodb table insert problem
I have set mysql tables to be innodb by default. Data inserted using sqlalchemy models never written to mysql innodb talbe. Innodb table is empty. If I try to insert data into the myisam tables, all the data get written to those tables. Here is the log of sqlalchemy insertion on innodb tables. For every insert, I see BEGIN and there aren't any corresponding commit each insert. Sqlalchemy log: INFO:sqlalchemy.engine.base.Engine.0x..cL:BEGIN INFO:sqlalchemy.engine.base.Engine.0x..cL:INSERT INTO lookup (username, shardname) VALUES (%s, %s) INFO:sqlalchemy.engine.base.Engine.0x..cL:['0', 'shard1'] INFO:sqlalchemy.engine.base.Engine.0x..4c:BEGIN INFO:sqlalchemy.engine.base.Engine.0x..4c:INSERT INTO lookup (username, shardname) VALUES (%s, %s) INFO:sqlalchemy.engine.base.Engine.0x..4c:['1', 'shard2'] == #!/usr/bin/env python import datetime, os from sqlalchemy import * from sqlalchemy import exceptions, sql from sqlalchemy.orm import * from sqlalchemy.orm.shard import ShardedSession from sqlalchemy.sql import operators from sqlalchemy import create_engine from blog_engine import * from lookup import Lookup from post import Post from post_config import sesslk from elixir import * import md5 from lookup_config import * def load_data(): load_data_lookup() def load_data_lookup(): session = None setup_all() for i in range(DATA): username1 = u%d % (i) hasha = md5.new() hasha.update(%s % username1) valuea = hasha.digest() remhexa = valuea.encode(hex) rema = long(remhexa, 16)% SHARD m1 = Lookup(username=%d % (i), shardname=shard_lookup_dict['%s' % rema]) sess = create_session_lookup() sess.begin() sess.save(m1) sess.commit() sess.clear() if __name__ == '__main__': load_data() === from elixir import * from sqlalchemy.orm.shard import ShardedSession from datetime import datetime from my_metadata import a_metadata import time __metadata__ = a_metadata __session__ = None class Lookup(Entity): using_options(tablename='lookup') id = Field(Integer(), primary_key = True) username = Field(String(30), nullable = False, unique=True) shardname = Field(String(100), nullable = False) --~--~-~--~~~---~--~~ 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] sqlalchemy connection pooling and mysql last_insert_id()
According my mysql, LAST_INSERT_ID() is connection specific, so there is no problem from race conditions. If I insert a record into a autoincremented table and do last_insert_id() on it, would there be a possibility where another insert happen just before selecting last_insert_id(). This won't be a problem with mysql if there isn't any connection pooling. Since sqlalchemy has support for connection pooling, would there be a chance where connection is shared with another insert just before selecting last_insert_id()? --~--~-~--~~~---~--~~ 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: Connecting to MySQL
On Thu, Jul 10, 2008 at 11:59 AM, jason kirtland [EMAIL PROTECTED] wrote: Lukasz Szybalski wrote: On Thu, Jul 10, 2008 at 11:26 AM, Heston James - Cold Beans [EMAIL PROTECTED] wrote: Session.add is a version 0.5 method, you're maybe running 0.4.6? In the 0.4.x series, it's going to be: Session.save() for objects that are to be newly added to the session Session.update() for objects that are already in the session, or Session.save_or_update() to have the library figure it out as it does for Session.add in v0.5.x Hi Rick, That's exactly what the problem was :-) Is there any reason I should avoid using 0.5? I'm running python 2.4 at the moment, are they compatible? Next quick question: I have a habbit of using 'created' and 'modified' columns on my tables, is there any way in which I can have the ORM update the dates for me when creating and modifying rows? From the link I sent you previously: sqlalchemy.Column('CreatedDate', sqlalchemy.Date, default=datetime.now().date()), sqlalchemy.Column('CreatedTime', sqlalchemy.Time, default=datetime.now().time()) Not so much. That'll stamp every inserted row with the same time- whatever time it was when python evaluated the Table definition. Here's a cross-db way to get timestamps: from sqlalchemy import Table, Column, DateTime, func Table('abc', metadata, ... Column('created', DateTime, default=func.now()), Column('updated', DateTime, onupdate=func.now())) What exactly is func ? Is that a function that just gets time or? Can I use onupdate=func.now().time() for time onupdate=func.now().date() for date I don't really prefer to have both date and time mixed in datetime field. Lucas --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---