[sqlalchemy] how to query one-to-many relationships, in a complicated way?

2014-07-02 Thread Chung WONG
Hi list, For this problem I am even having trouble think of a proper subject for it. I try my best to express as clear as possible and sorry for any confusions. Say there are three classes with relationship defined as below: class User(Base): __tablename__ = 'users' id = Column(Integer,

[sqlalchemy] getting error with column name end using geoalchemy2

2014-06-21 Thread Chung WONG
Hi list, I am encountering a very strange error and I am scratching my head and got no idea what is going on. class Line(Base): __tablename__ = 'lines' id = Column(Integer, Sequence('line_id_seq'), primary_key=True) start = Column(Geometry('POINT'), nullable=False, *index=False*)

[sqlalchemy] what is the best way to test if a record exists in table?

2014-03-31 Thread Chung WONG
For example, session.query(User).filter(User.name == 'fred').first() q = session.query(User).filter(User.name == 'fred')session.query(q.exists()) session.query(exists().where(User.name == 'fred')).scalar() are they perform pretty much the same? or is there a better way for checking? Thanks

[sqlalchemy] how to update two fieds from two tables where one depends on the other simultaneously

2013-12-03 Thread Chung WONG
Hi all, Say there are two tables defined as below: class Topic(Base): __tablename__ = 'topics' id = Column(Integer,Sequence('topic_id_seq'), primary_key=True) *last_posted_at=Column(DateTime,default=func.now())* created_at=Column(DateTime,default=func.now())

[sqlalchemy] How to do datetime arithmetic in Column()?

2013-11-27 Thread Chung WONG
Hi list, currently I have two fields: START = Column(DateTime,default=func.now()) END = Column(DateTime,default=func.now() + 30 ) apparently the default syntax in END field is not correct. How do I set the default value of END field, say 30 days after the value of START field? thanks

[sqlalchemy] Re: Inheritance configuration question on saving

2013-10-28 Thread Chung WONG
:59 PM UTC+11, Chung WONG wrote: class User(Base): from sqlalchemy.dialects.postgresql import INET __tablename__ = 'users' id = Column(Integer,Sequence('user_id_seq'), primary_key=True) first_name = Column(Unicode(255),nullable=False) last_name = Column(Unicode(255

[sqlalchemy] Inheritance configuration question on saving

2013-10-27 Thread Chung WONG
class User(Base): from sqlalchemy.dialects.postgresql import INET __tablename__ = 'users' id = Column(Integer,Sequence('user_id_seq'), primary_key=True) first_name = Column(Unicode(255),nullable=False) last_name = Column(Unicode(255),nullable=False) created_at =

Re: [sqlalchemy] Inheritance configuration question on saving

2013-10-27 Thread Chung WONG
I just tested it and it just worked like a charm. SQL crafting made easy! Thanks Mike On Monday, October 28, 2013 3:41:48 PM UTC+11, Michael Bayer wrote: On Oct 27, 2013, at 11:06 PM, Chung WONG wch...@gmail.com javascript: wrote: class User(Base): from