For eg where does this part go in the sample webpy doc
http://rafb.net/p/u7ahBK46.htmlReflecting tables
If you want SQLAlchemy to read the table structure from existing database
tables so you don't have to specify the columns, you'll have to put the
table definitions and the mapper calls inside init_model because they depend
on a live database connection. The ORM class defintions do not have to be in
init_model. So you could do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import sqlalchemy as sa
from sqlalchemy import orm
from myapp.model import meta
from myapp.model import records
def init_model(engine):
"""Call me before using any of the tables or classes in the model."""
sm = orm.sessionmaker(autoflush=True, transactional=True, bind=engine)
meta.engine = engine
meta.Session = orm.scoped_session(sm)
records.t_record = sa.Table("Record", meta.metadata,
autoload=True, autoload_with=engine)
orm.mapper(records.Record, records.t_record)
On Thu, Jul 10, 2008 at 9:41 PM, Chen Memo <[EMAIL PROTECTED]> wrote:
>
> On Fri, Jul 11, 2008 at 8:49 AM, paul jobs <[EMAIL PROTECTED]> wrote:
> > http://rafb.net/p/u7ahBK46.html
> >
> > This is what i have so far
> > do help me
> >
> > I need to query tables that are already there created using normal sql
> >
> > Can someone show how to query a simple table and construct results
> > similar to db.select or db.query
> > for
> > CREATE TABLE todo (
> > id serial primary key,
> > title text,
> > created timestamp default now(),
> > done boolean default 'f' );
> >
>
> have u ever read the doc of sqlalchemy ? It's a little complicated to
> understand, but it's very easy to use.
>
> you could use it like this:
> >>> for user in session.query(User).filter("id<224").order_by("id").all():
> ... print user.name
>
> it's result set is also a list, so you could use it just like
> db.query. and there is not the mail list of sqlalchemy, so you
> probably not get responses here.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---