[sqlalchemy] Re: SQLalchemy coding style

2007-10-30 Thread McA

Hi all,

thank you for your comments.
I really expected to get comments from more people.
But probably I'm concerned about something you don't have to. ;-)

So, I'll wait.

Best regards
Andreas


--~--~-~--~~~---~--~~
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: SQLalchemy coding style

2007-10-30 Thread Lukasz Szybalski

On 10/30/07, McA [EMAIL PROTECTED] wrote:

 Hi all,

 thank you for your comments.
 I really expected to get comments from more people.
 But probably I'm concerned about something you don't have to. ;-)

 So, I'll wait.

it seems better to use:
import sqlalchemy

and in code do:
sqlalchemy.select(...)

if you start using import * from sqlalchemy then your code will get
confusing really quick. For example you won't know which select() you
talk about if you use pure sqlaclhemy or assign_mapper. So it is
preferred that you use
import sqlalchemy
or
import sqlalchemy as sa
at all times.

Lucas
-- 
-- 
Vim auto completion for python
http://lucasmanual.com/mywiki/FrontPage#head-8ce19b13e89893059e126b719bebe4ee32fe103c
TurboGears from start to finish:
http://www.lucasmanual.com/mywiki/TurboGears

--~--~-~--~~~---~--~~
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: SQLalchemy coding style

2007-10-30 Thread Rick Morrison
If you don't want to pollute the current namespace, then make an indirect
reference.

1) Make a module of your own, say db.py

2) In db.py:
 ...
  from sqlalchemy import *
  from sqlalchemy.orm import *
 ...
  table1 = Table('footable', ...)
 ...
  # other table defs, mappers, classes, etc.

3) In your non-polluted code:
 ...
  import db# your indirect reference
 ...
 ...

  qry = db.select([db.table1.c.col], db.table1.c.col2 == 'foo')

So now you have most of the convenience of all of the SqlAlchemy names all
loaded, but your namespace only contains the 'db' indirect reference. You
still need to worry about the 'db' namespace being polluted, but at least
it's only in that one module.



On 10/29/07, McA [EMAIL PROTECTED] wrote:


 Hi all,

 I'm intersted in using sqlalchemy and started to read the manuals.
 I didn't find a hint for my question, so I'm asking here. I hope it's
 not too annoying.

 Most code examples in the documentation use something like this
 from sqlalchemy. import 

 My question is: Is this the good/proper way to import the sqlalchemy
 stuff.
 I'm concerned about polluting the current namespace. I could assume
 that
 class names like 'Table' are too common to reserve them for the
 sqlalchemy
 classes.

 What would you recommend? How are the gurus out there using
 sqlalchemy?

 Thanks in advance.

 Best regards
 Andreas Mock


 


--~--~-~--~~~---~--~~
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: SQLalchemy coding style

2007-10-29 Thread Paul Johnston
Hi,

I have a python file for all the table and class definitions (model.py). In
that I do from sqlalchemy import *, and that's ok as in that one file I know
not to use names like Table.

In my other python files I just import classes from model.py, and specific
bits of sqlalchemy. Ok, occasionally I get lazy and just do an import * :)

Paul



On 10/29/07, McA [EMAIL PROTECTED] wrote:


 Hi all,

 I'm intersted in using sqlalchemy and started to read the manuals.
 I didn't find a hint for my question, so I'm asking here. I hope it's
 not too annoying.

 Most code examples in the documentation use something like this
 from sqlalchemy. import 

 My question is: Is this the good/proper way to import the sqlalchemy
 stuff.
 I'm concerned about polluting the current namespace. I could assume
 that
 class names like 'Table' are too common to reserve them for the
 sqlalchemy
 classes.

 What would you recommend? How are the gurus out there using
 sqlalchemy?

 Thanks in advance.

 Best regards
 Andreas Mock


 


--~--~-~--~~~---~--~~
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: SQLalchemy coding style

2007-10-29 Thread Nebur


 What would you recommend? How are the gurus out there using
 sqlalchemy?

I don't know what the gurus are doing. I'll answer as long as none of
them does :-)
It's probably what you're assuming already:
Mapped classes can be treated as Active Records. Usually, I'm
encapsulating these active records in their own modules. These modules
can be seen as a layer directly above the relational DB, and they have
all SQLAlchemy imports encapsulated. (99% in practice ;-)
If you can't encapsulate, Pythons import machinery will allow us to
use names like sa.Table ... so I can't see a pollution problem (at
least, not worse than with any other library.)
Regards-
 Ruben


--~--~-~--~~~---~--~~
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: SQLalchemy coding style

2007-10-29 Thread Werner F. Bruhin

McA wrote:
 Hi all,

 I'm intersted in using sqlalchemy and started to read the manuals.
 I didn't find a hint for my question, so I'm asking here. I hope it's
 not too annoying.

 Most code examples in the documentation use something like this
   
 from sqlalchemy. import 
   

   
I am just experimenting with sqlalchemy, but I am pretty sure to start 
using it soon, I wondered about this too, to me it was confusing to look 
at code and not easily able to see where things come from.

Having seen the wxPython project move to use the namespace as of 2.6 
(with I think two transition releases), I have done all the tests so far 
doing the following type of import and corresponding code.  This has not 
caused any problems so far and to while a little bit more typing makes 
the code more readable, especially for newbies.

But I wonder why this is not done by everyone, i.e. what are the reasons 
not to do it this way?

import sqlalchemy as sa
import sqlalchemy.orm as sao

metadata = sa.MetaData()

cbbottle_table = sa.Table( u'cbbottle', metadata,
sa.Column( u'cbbottleid', sa.Integer(), 
sa.Sequence('gen_cbbottle_cbbottleid'),
primary_key= True, nullable= False),
sa.Column( u'maturityfirst', sa.Integer()),
sa.Column( u'maturitybest', sa.Integer()),
sa.Column( u'maturitypast', sa.Integer()),
...
sa.Column( u'fk_cbvintageid', sa.Integer(), 
sa.ForeignKey(u'cbvintage.cbvintageid')),
)

Werner
 My question is: Is this the good/proper way to import the sqlalchemy
 stuff.
 I'm concerned about polluting the current namespace. I could assume
 that
 class names like 'Table' are too common to reserve them for the
 sqlalchemy
 classes.

 What would you recommend? How are the gurus out there using
 sqlalchemy?

 Thanks in advance.

 Best regards
 Andreas Mock


 


   


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---