open_db#

Open a database of the environment, for this and later transactions.

Synopsis#

my $main  = $txn->open_db;                       # the unnamed database
my $users = $txn->open_db('users', MDB_CREATE);

What you get back#

A Peta::LMDB::DB handle. It belongs to the environment: once the transaction that opened it commits (a read one, too), every later transaction can use it.

Flags#

  • MDB_CREATE - create a named database that does not exist (in a write transaction).

  • MDB_DUPSORT - keys may hold several values, kept sorted; MDB_DUPFIXED, MDB_INTEGERDUP, MDB_REVERSEDUP refine it.

  • MDB_INTEGERKEY - keys are unsigned integers; MDB_REVERSEKEY - keys compare from their last byte.

Edge cases#

  • A named database needs the environment opened with maxdbs; one more than that croaks MDB_DBS_FULL.

  • A name that does not exist, without MDB_CREATE, croaks MDB_NOTFOUND.

  • A handle opened in a transaction that aborts is gone with it.

See also#

  • drop - empties or deletes a database

  • Peta::LMDB::DB - a database’s own order