def gets(self): method_name = 'TokenMapper.gets' log.info('{}: initialization.'.format(method_name)) tokens = [] for db_token in Tokens.select(): tokens.append(self.mapper(db_token)); log.info('{}: end.'.format(method_name)) return tokens
def update(self, token_object): method_name = 'TokenMapper.update' log.info('{}: initialization.'.format(method_name)) query = Tokens.update(token=token_object.token, lemma_id=token_object.lemma_id, pos_id=token_object.pos_id, syllables=token_object.syllables, length=token_object.length).where(Tokens.id==token_object.id) log.info('{}: end.'.format(method_name)) if query.execute() != 1: return True else: return False
def insert(self, token_object): method_name = 'TokenMapper.insert' log.info('{}: initialization.'.format(method_name)) query = Tokens.insert(token=token_object.token, lemma_id=token_object.lemma_id, pos_id=token_object.pos_id, syllables=token_object.syllables, length=token_object.length) token_object.id = query.execute() # Return new id log.info('{}: end.'.format(method_name)) return token_object
def get(self, token_id): method_name = 'TokenMapper.get' log.info('{}: initialization.'.format(method_name)) try: token_object = Tokens.get(Tokens.id==token_id) log.info('{}: end.'.format(method_name)) return self.mapper(token_object) except Exception as e: log.info('TokenDoesNotExist errno={}: strerror{}.'.format(e.errno, e.strerror)) log.info('{}: end.'.format(method_name)) raise Exception('TokenDoesNotExist errno={}: strerror{}.'.format(e.errno, e.strerror))