Creating Indexes need much improvement
So to be so harsh, but I spend 3 hours trying to avoid the need to create a new class for each index. All indexes are sharing the same logic.
What I tried to aachief: Create many indexes like in your tut2 (add obj to index if key exists) at runtime without creating a new class for each index, since all indexes are sharing the same logic.
What I tried:
I tried many, many different approaches, but all failed. I even tried generating code on the fly. At last I can out with this one:
def __init__(self, path, name, _key, _key_format, *args, **kwargs): self._key = _key self._key_format = _key_format kwargs['key_format'] = _key_format super(BaseIndex, self).__init__(path, name, *args, **kwargs)
[...] idx = BaseIndex(db.path, name, key, key_format) db.add_index(idx)
This works fine for creating the index, but opening the database later fails: File "lib/python2.7/site-packages/CodernityDB/database.py", line 203, in _read_index_single ind_obj = globals()_class TypeError: init() takes at least 5 arguments (3 given)
Please implement a decent way to create indexes!