def create_index(self, field_to_index: str) -> None: index_tree = BPlusTree( f'db_files/{self.name}_order_by_{field_to_index}.db', order=50) db_data = read_from_json("db_files/db.json") if field_to_index in db_data[self.name]['indexes']: return num_of_files = db_data[self.name]['num of files'] primary_key = db_data[self.name]['primary key'] if primary_key == field_to_index: for file_num in range(num_of_files): path = f"db_files/{self.name}_{file_num + 1}.json" file_data = read_from_json(path) for k in file_data.keys(): print(k) index_tree[k] = path else: for file_num in range(num_of_files): path = f"db_files/{self.name}_{file_num + 1}.json" file_data = read_from_json(path) for v in file_data.values(): print(v) index_tree[v[field_to_index]] = path index_tree.close() db_data[self.name]['indexes'] += field_to_index
def main(): tree = BPlusTree('/tmp/bplustree.db', order=50) tree[1] = b'foo' tree[2] = b'bar' print(tree.get(3), tree[1], list(tree.keys())) tree.close()
print('rece data:'+data) if data.strip() == '' or data.strip() == 'exit': connection.close() connection, address = SOCKET.accept() continue command, key, value = parse_message(data) if command == 'STATS': response = handle_stats() elif command in ('GET', 'GETLIST', 'INCREMENT', 'DELETE'): response = COMMAND_HANDERS[command](key) elif command in ( 'PUT', 'PUTLIST', 'APPEND', ): response = COMMAND_HANDERS[command](key, value) else: response = (False, 'Unknown command type {}'.format(command)) update_stats(command, response[0]) data = '{};\n{}\n'.format(response[0], response[1]) connection.sendall(bytearray(data, 'utf-8')) connection.close() if __name__ == '__main__': try: main() except KeyboardInterrupt: tree.close()