On Monday, March 18, 2013 5:25:36 PM UTC-4, Peter Herndon wrote:
>
> Hi all,
>
> I'm new to SQLAlchemy, and looking for some advice on how to approach 
> working with an existing database. The database will not be managed by 
> Python, and I will need to maintain whatever library I write to keep up 
> with the occasional schema change. I am looking to write a more-or-less 
> definitive database access layer for myself and others to use if and when 
> we write applications in Python -- the company is not primarily a Python 
> shop. 
>
> What's my best approach for building this library? Should I use 
> Declarative, or should I use classical mapping -- which would be better, 
> easier to maintain, easier for others to use? Should I be writing out the 
> classes, or should I rely on reflection? Speaking of reflection, I've been 
> using it to analyze what SQLAlchemy thinks of the schema. For a given table 
> created by reflection, I'm seeing _autoincrement_column, columns, 
> foreign_keys, indexes, and primary_key -- are there other table attributes 
> I should be inspecting?
>
> Thanks for your advice!
>
> ---Peter
>

Hi Peter,
I think using a the declarative reflected style is a great way to integrate 
an existing database into your application. It sounds like you are doing 
this already, but in case you are not the reflection setup is documented at 
http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html#using-reflection-with-declarative.
 
It's very easy to have it populate all of your models with the correct 
table attributes using the DeferredReflection base class. Then you just 
have to make (almost empty) class definitions for each model. In theory you 
could even make it so that the table name is inferred from the name of the 
Model class, but in practice I found this to be annoying (I would 
constantly forget how the table names compared to the class names).

--
Jason

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to