[sqlalchemy] classes in separate files
Hi, could someone advice me, please, how to split classes into individual files? I'm studying the documentation: Creating Table, Class and Mapper All at Once Declaratively http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table- class-and-mapper-all-at-once-declaratively. If I keep all the classes in the same file, the program works fine. If I try to split them into individual files, I'm getting errors like NoReferencedTableError: Could not find table 'users' with which to generate a foreign key Are there some Best practices of how to do this? Thanks. c. PS: All the classes are in their individual modules in a package called database: database /dbinit.py - common initialization (ex. Base = declarative_base()) /mailevt.py - class MailEvent /mailogrec.py - class MailLogEvent (foreign keys to Server, ObjAddress, MailEvent) /objaddr.py - class ObjAddress /server.py - class Server /user.py - class User /useraddr.py - class UserAddress (foreign key to User, ObjAddress) /vpnlogrec.py - class VpnLogRecord (foreign key to User, Server) /weblogrec.py - class WebLogRecord (foreign key to User, Server) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: classes in separate files
Yes, of course. This feature is provided by dbinit.py (mentioned at the bottom of the orig. message). c. On 9 Ún, 10:42, King Simon-NFHD78 simon.k...@motorola.com wrote: Are all your classes using the same declarative_base? I think this is necessary so that the tables use the same metadata and things like foreign keys can be resolved. I would probably do this by creating database/base.py that contains something like: from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() And then your other modules would import Base from there. Does that make any sense? Simon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: INSERT ... ON DUPLICATE KEY UPDATE
Thank you for the reply. However, this solution (though I'm ready to use it) would create a lot of SQL queries comparing it with simple INSERT ... ON DUPLICATE KEY UPDATE. On the other hand, I admit the INSERT ... IN DUPLICATE KEY UPDATE might not be available in other DBs. I would like the application would be independent of the database engine bellow. So... is there some way how to achieve this while keeping number of SQL queries low? :-) (The number of objects handled this way is about 20 000.) Thanks c. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] INSERT ... ON DUPLICATE KEY UPDATE
hello, i'm trying to use sqlalchemy 0.5.1 with python 2.5.4 on windows. and mysql 5.1. the task is simple: to keep fresh information about our servers. i can get a list of server names from AD, get some info about them and insert them into DB using Session.add(). if i run the script for the first time, it works fine. however, the next run fails: sqlalchemy.exc.IntegrityError: (IntegrityError) (1062, Duplicate entry... the table looks like this: 'id', 'int(11)', 'PRIMARY KEY', 'auto_increment' 'name', 'varchar(16)', 'UNIQUE' 'ip_address', 'varchar(16)' ... (some other columns which are not important) if i want to keep the data up to date, i need to update them if they already exist in DB. if i would use plain (literal) sql, i could execute insert in $SUBJ. but i would like to use sqlalchemy's native solution if it's possible. however, i don't know how to do this. can anyone help me? thanks c. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---