How to use the lmdb.Transaction function in lmdb

To help you get started, we’ve selected a few lmdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsindex / blog / search_lmdb.py View on Github external
parser = OptionParser()
    parser.add_option("--verbose", action="store_const", const=1, dest="verbose", help="verbose mode")
    parser.add_option("-d", "--db", dest="dbpath",help="db path", metavar="DB")
    (options, args) = parser.parse_args()

    if options.verbose == 1 : VERBOSE = 1

    db_path = options.dbpath
    if db_path == None :
        parser.print_help()
        sys.exit(1)


    # env == db coz max_dbs=0
    env = lmdb.Environment(db_path,map_size=24*(1023**3),subdir=False,readonly=True,create=False,max_dbs=0,lock=False)
    txn = lmdb.Transaction(env,db=None,write=False)

    startTime = time.time()
    
    linecount = 0
    while 1 :
        try : line = sys.stdin.readline()
        except KeyboardInterrupt : break
        if not line : break
        try : line = line.strip()
        except : continue
        if not line : continue
        linecount += 1
        if linecount % 1000 == 0 :
            sys.stderr.write("[linecount]" + "\t" + str(linecount) + "\n")

        key,value = line.split('\t',1)
github dsindex / blog / make_lmdb.py View on Github external
parser.add_option("--verbose", action="store_const", const=1, dest="verbose", help="verbose mode")
    parser.add_option("-d", "--db", dest="dbpath",help="db path", metavar="DB")
    (options, args) = parser.parse_args()

    if options.verbose == 1 : VERBOSE = 1

    db_path = options.dbpath
    if db_path == None :
        parser.print_help()
        sys.exit(1)

    startTime = time.time()

    # env == db coz max_dbs=0
    env = lmdb.Environment(db_path,map_size=24*(1023**3),subdir=False,readonly=False,create=False,max_dbs=0,lock=False)
    txn = lmdb.Transaction(env,db=None,write=True)
    
    linecount = 0
    while 1 :
        try : line = sys.stdin.readline()
        except KeyboardInterrupt : break
        if not line : break
        try : line = line.strip()
        except : continue
        if not line : continue
        linecount += 1
        if linecount % 1000 == 0 :
            sys.stderr.write("[linecount]" + "\t" + str(linecount) + "\n")

        key,value = line.split('\t',1)
        if not key or not value : continue
github CZ-NIC / knot / scripts / pykeymgr.py View on Github external
def list_zones(dirname):
	print "dirname:", dirname
	env = lmdb.open(dirname, max_dbs=2, map_size=500*1024*1024)
	db_zones = env.open_db("zones_db", dupsort=True)
	zonedict = dict()
	with lmdb.Transaction(env, db_zones, write=False) as txn_zones:
		for k, v in txn_zones.cursor():
			dn = dname2str(k)
			ki = v.rstrip("\x00")
			try:
				zonedict[dn].insert(0, ki)
			except KeyError:
				zonedict[dn] = [ ki ]
	for zone in zonedict.keys():
		print zone, zonedict[zone]
github oberstet / scratchbox / python / lmdb / database.py View on Github external
def __enter__(self):
        assert(self._txn is None)
        self._txn = lmdb.Transaction(self._env, write=self._write)
        self.attach()
        return self
github CZ-NIC / knot / scripts / pykeymgr.py View on Github external
def zone2keyids(dirname, zone_str):
	env = lmdb.open(dirname, max_dbs=2, map_size=500*1024*1024)
	db_zones = env.open_db("zones_db", dupsort=True)
	ret = [ ]
	zone = str2dname(zone_str)
	with lmdb.Transaction(env, db_keys, write=False) as txn_keys:
		curs = txn_keys.cursor()
		r = curs.set_range(Keykey.from_params(1, zone, None).getRaw())
		while r:
			k = Keykey(curs.key())
			if k.getZone() != zone:
				break
			ret.append(k.getKeyid())
			r = curs.next()
	return ret
github CZ-NIC / knot / scripts / pykeymgr.py View on Github external
def update_param(dirname, zone_str, key_spec, param_name, new_val):
	#zone gets actually ignored
	if param_name in ("keytag", "algorithm") and not opt_force:
		print "Error: modification of", param_name, "requires force option"
		return False

	env = lmdb.open(dirname, max_dbs=2, map_size=500*1024*1024)
	db_keys = env.open_db("keys_db")
	something_updated = False
	with lmdb.Transaction(env, db_keys, write=True) as txn_keys:
		for k, v in txn_keys.cursor():
			try:
				kp = Keyparams(v)
				if key_matches(k, kp, key_spec, "all"):
					kp.setByParamName(param_name, new_val)
					txn_keys.put(k, kp.getRaw(), dupdata=False, overwrite=True)
					something_updated = True
					return
			except AssertionError:
				pass # some key-val which is not proper key param
	print "Error updating key parameter (probably the key not found)"
github CZ-NIC / knot / scripts / pykeymgr.py View on Github external
for key in keys["keys"]:
			dbk3 = Keykey.from_params(1, zname, key["id"]).getRaw()

			infty = 0x00ffffffffffff00 # time infinity, this is year 142'715'360

			dbv3 = Keyparams.from_params(key["public_key"], key["keytag"],
			                             key["algorithm"], key["ksk"], [
			                               arr_ind2unix(key, "created", 0),
			                               arr_ind2unix(key, "publish", 0),
			                               arr_ind2unix(key, "active", 0), # taking active for ready
			                               arr_ind2unix(key, "active", 0),
			                               arr_ind2unix(key, "retire", infty),
			                               arr_ind2unix(key, "remove", infty)
			                             ]).getRaw()

			with lmdb.Transaction(env, db_keys, write=True) as txn_keys:
				txn_keys.put(dbk3, dbv3, dupdata=False, overwrite=True)

	except (KeyError, KeyboardInterrupt, TypeError):
		print "Warning: not imported ", fname
		return False

	return True
github tensorwerk / hangar-py / src / hangar / arrayset.py View on Github external
db where the newly added staged hash data records are stored
            default_schema_backend : str
                backend code to act as default where new data samples are added.
            **kwargs:
                See args of :class:`ArraysetDataReader`
        """
        super().__init__(*args, **kwargs)

        self._fs[self._dflt_backend].backend_opts = self._dflt_backend_opts

        self._stagehashenv = stagehashenv
        self._dataenv: lmdb.Environment = kwargs['dataenv']
        self._hashenv: lmdb.Environment = kwargs['hashenv']

        self._TxnRegister = TxnRegister()
        self._hashTxn: Optional[lmdb.Transaction] = None
        self._dataTxn: Optional[lmdb.Transaction] = None
github oddjobz / pynndb / pynndb / transaction.py View on Github external
def __init__(self, database, write=False, buffers=False):
        self._transactions = []
        self._coc = [database.node]
        self._tid = None
        self._replicated = False
        self._db = database
        self._txn = lmdb.Transaction(self._db.env, write=write, buffers=buffers)