views:

164

answers:

0

Hi!

I try to get all row from table.

in controler i try to

meta.Session.query(User).all()

But the result is [, ] In this table i heve 2 rows.

I get this model for the table:

import hashlib
import sqlalchemy as sa
from sqlalchemy import orm

from allsun.model import meta

t_user =  sa.Table("users",meta.metadata,autoload=True)

class Duplicat(Exception):
    pass
class LoginExistsException(Exception):
    pass
class EmailExistsException(Exception):
    pass

class User(object):
    def loginExists(self):
        try:
            meta.Session.query(User).filter(User.login==self.login).one()
        except orm.exc.NoResultFound:
            pass
        else:
            raise LoginExistsException()

    def emailExists(self):
        try:
            meta.Session.query(User).filter(User.email==self.email).one()
        except orm.exc.NoResultFound:
            pass
        else:
            raise EmailExistsException()


    def save(self):
        meta.Session.begin()
        meta.Session.save(self)
        try:
            meta.Session.commit()
        except sa.exc.IntegrityError:
            raise Duplicat()

orm.mapper(User, t_user)