Search Results

Search found 3 results on 1 pages for 'hadrien'.

Page 1/1 | 1 

  • SQLAlchemy: a better way for update with declarative?

    - by hadrien
    I am a SQLAlchemy noob. Let's say I have an user table in declarative mode: class User(Base): __tablename__ = 'user' id = Column(u'id', Integer(), primary_key=True) name = Column(u'name', String(50)) When I know user's id without object loaded into session, I update such user like this: ex = update(User.__table__).where(User.id==123).values(name=u"Bob Marley") Session.execute(ex) I dislike using User.__table__, should I stop worrying with that? Is there a better way to do this? Thanx!

    Read the article

  • SQLAlchemy: an efficient/better select by primary keys?

    - by hadrien
    Yet another newbie question.. Let's say I have an user table in declarative mode: class User(Base): __tablename__ = 'user' id = Column(u'id', Integer(), primary_key=True) name = Column(u'name', String(50)) When I have a list of users identifiers, I fetch them from db with: user_ids = [1, 2, 3, 4, 5] users = Session.query(User).filter(User.id.in_(user_ids)).all() I dislike using in_ because I think I learned it has bad performance on indexed fields (is that true/false?). Anyway, is there a better way doing that query? Thanks!

    Read the article

  • Hibernate Criteria API: get n random rows

    - by hadrien
    I can't figure out how to fetch n random rows from a criteria instance: Criteria criteria = session.createCriteria(Table.class); criteria.add(Restrictions.eq('fieldVariable', anyValue)); ... Then what? I can't find any doc with Criteria API Does it mean I should use HQL instead? Thanx! EDIT: I get the number of rows by: int max = criteria.setProjecxtion(Projections.rowCount()).uniqueResult(); How do I fetch n random rows with indexes between 0 and max? Thx again!

    Read the article

1