def main(argv=sys.argv): if len(argv) != 2: usage(argv) config_uri = argv[1] setup_logging(config_uri) settings = get_appsettings(config_uri) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: model = UsersTable(username='******', name_first='Robert') DBSession.add(model)
def delete(self, user_id): try: user = DBSession.query(UsersTable).filter(UsersTable.uid == user_id).one() except: return {'status': '2', 'data': 'No User Found'} try: status = DBSession.delete(user) transaction.commit() except: transaction.abort() # This seems necessary for the functional tests # to run return {'status': '1', 'data': 'Something Went Wrong'} return {'status': '0', 'data': 'Create User Successful'}
def get_user_by_id(self, user_id): result = DBSession.query(UsersTable).filter(UsersTable.uid == user_id) try: user = build_user(result.one()) except: user = None return user
def create(self, user_info): user = UsersTable(username=user_info['username']) status = DBSession.add(user) try: transaction.commit() except: return {'status': '1', 'data': 'Username Exists'} return {'status': '0', 'data': 'Create User Successful'}
def update_by_id(self, user_id, user_info): try: user = DBSession.query(UsersTable).filter(UsersTable.uid == user_id).update({'username':user_info['username']}) transaction.commit() except: return {'status': '1', 'data': 'Username Exists'} return {'status': '0', 'data': 'Update User Successful'}
def get_all(self): users = DBSession.query(UsersTable).all() return [build_user(u) for u in users]