Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, _txn, _db, _readonly=True):
self._txn = _txn
self._db = _db
self._readonly = _readonly
self._cursor = lmdb.Cursor(_db, _txn)
:param name: The name of the index to reindex
:type name: str
:param txn: An open transaction
:type txn: Transaction
:return: Number of index entries created
:rtype: int
"""
if name not in self._indexes: raise xIndexMissing
index = self._indexes[name]
with self.begin() as transaction:
txn = txn if txn else transaction
count = 0
self._indexes[name].empty(txn)
with lmdb.Cursor(self._db, txn) as cursor:
if cursor.first():
while True:
record = loads(cursor.value().decode())
if index.put(txn, cursor.key().decode(), record):
count += 1
if not cursor.next():
break
return count
def tables():
result = []
with lmdb.Cursor(self._db, txn) as cursor:
if cursor.first():
while True:
name = cursor.key().decode()
if all or name[0] not in ['_', '~']:
result.append(name)
if not cursor.next():
break
return result
def cursor(self, txn=None):
"""
Return a cursor into the current index
:param txn: Is an open Transaction
:type txn: Transaction
:return: An active Cursor object
:rtype: Cursor
"""
return lmdb.Cursor(self._db, txn)