On Apr 21, 7:04 pm, [email protected] wrote:

> - Have a script that will connect to the database, read the schema,  
> and generate a single file. This will be a python script that  
> generates the definitions of all the classes, relationships, etc.

I know you dont' think sqlautocode does what you want, but have you
tried one of the earlier versions of it.
They are single file scripts which are very easy to read and modify to
do what you want.

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/AutoCode

Pretty much the code is all there to reflect the database schema, and
generate the
sqlalchemy python Table definitions for each database table.

You can then iterate through the metadata yourself and generate what
ever you please.

I guess it depends if you are going the standard SA table/mapping way
or the sqlalchemy.ext.declarative way

> - I want to use reflection whenever possible.
Not sure exactly which reflection you want here but my experience with
a database of about 30+ tables, it's so much faster for development
to have a static SA table definitions file then to have it reflect on
every server reload. I even tried to reflect then pickle, but found
 that having a hard copy of what SA thinks the database is was
invaluable for testing/debugging etc.

>
> - I want this output file to be considered read only such that when I  
> modify the database, I can rerun the script and regenerate it with the  
> changes.
that's the only way to do it i imagine.

>
> - I want to create a second python script that will contain one class  
> definition for each in the first file. For example, let's say I have a  
> table called "plate". The first file will contain the full definition  
> for a class called "Plate_". The second file might contain:
>
> class Plate(Plate_): pass
>
> The second definition is a subclass of the first where I can put  
> custom logic (if I need any) for each class. This is the class I will  
> use in my scripts. I will then import this file from the many scripts  
> I need to write that use this database.
>
> (If anyone here has used WebObjects they'll know what I'm trying to do  
> here.)


Just wondering why you need both ? (unless you are going the
sqlalchemy.ext.declarative way.)

If you are using the standard table/mapping, your model classes don't
have to extend explicitly an SA base class.
Also, SA can work with a simple class definition like

class Plate(object):
    pass

and it auto injects everything itself, when you do the mapping. It's
not like java where you generate
setters and getters for every database column.


> I've looked at Elixir, SQLSoup, and sqlautocode. I don't think any of  
> these do quite what I'm trying to do here. I've only started to play  
> with SQLAlchemy, and I'm a little frustrated at how much code I need  
> to write to start using it, code that can certainly (and should) be  
> generated.

I think it's good to do some things manually when you first start out.
Heck, it's not really that much code.  I guess you come from WO which
generated pretty much everything.
Are you going to ask for a CRUD generator next :-)

> I'd appreciate any advice on how best to approach this. Also, please  
> let me know if I'm missing something from existing tools.
>
> Cheers,
>
> Demitri

Cheers,

Huy

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to