if key1 and key2: query_statement = db_session.query(cls1_alias, cls2_alias)\ .outerjoin(cls2_alias, getattr(cls1_alias, key1) == getattr(cls2_alias, key2))\ .order_by(cls1_alias.id) sql_logger.debug(query_statement) return query_statement.all() else: query_statement = db_session.query(cls1_alias, cls2_alias)\ .outerjoin(cls2_alias)\ .order_by(cls1_alias.id) sql_logger.debug(query_statement) return query_statement.all() if __name__ == '__main__': init_db() from model.member import Member # # member = Member(u'Lee', 12345678901, 'abcdefg', '*****@*****.**') # print 'add status: ', add(member) # # members = query_all(Member) # print 'query_all result: ', members # # member = query_by_id(Member, 1) # print 'query_by_id result: ', member # # members = query_by_condition(Member, name=u'Lee') # print 'query_by_condition result: ', members # # print 'delete status: ', delete(members[0])
# coding:utf-8 __author__ = 'xinchun.li' __emails__ = '*****@*****.**' from flask import Flask app = Flask(__name__) from view import hierarchy_view app.register_blueprint(hierarchy_view.bp, url_prefix='/%s' % hierarchy_view.ROOT_PATH) from view import helloworld_view app.register_blueprint(helloworld_view.bp, url_prefix='') from dao import database @app.teardown_appcontext def shutdown_session(exception=None): database.shutdown_session() if __name__ == '__main__': database.init_db() app.debug = True app.run()