class

LMDB::Environment

Inherits LMDB::Disposable / Reference / Object

Class for an LMDB database environment. An environment may contain multiple databases, all residing in the same shared-memory map and underlying disk file. A database is a key-value table.

An environment, and its databases, is usually stored in a directory which contains two files:

  • data.mdb: all records from all databases of this environment.
  • lock.mdb: state of transactions that may be going on in the environment.

To write to the environment a Transaction must be created. One simultaneous write transaction is allowed, however there is no limit on the number of read transactions even when a write transaction exists.

Example:

env = LMDB.new "mydbdir"
db = env.database "mydb"
# ...
env.close

Constructors

new(path : String, flags : Flag = Flag::NoTls, mode : FileMode = FileMode.new(420), max_dbs : Int = 0, map_size : Int = 0)

Create and opens a new Environment under path with given options.

  • max_dbs: sets the maximum number of named databases in the environment.
  • mode: the POSIX permissions to set on created files.
  • map_size: sets the size of the memory map to be allocated for this environment, in bytes. The size should be a multiple of the OS page size. The default is 10485760 bytes. The size of the memory map is also the maximum size of the database.
Source

Instance methods

clear_flags(flags : Flag)

Clears environment flags.

Source
database(flags : Database::Flag = LMDB.db_flags(None)) : Database

Opens and returns the main Database associated with self. Each environment has an unnamed database.

A database needs to be opened (or created) within a transaction. If a pending transaction for this environment exists, it will be used for this purpose. Otherwise, a new ReadOnlyTransaction is created.

If a transaction is created specifically, it will be commited before the Database is returned. Otherwise, no particular action on the existing pending transaction is performed.

Source
database(flags : Database::Flag = LMDB.db_flags(None), &)

Opens and yields the main Database associated with self. Each environment has an unnamed database.

A database needs to be opened (or created) within a transaction. If a pending transaction for this environment exists, it will be used for this purpose. Otherwise, a new ReadOnlyTransaction is created.

If a transaction is created specifically, it will be commited when the block goes out of scope. Otherwise, no particular action on the existing pending transaction is performed.

Source
database(name : String, flags : Database::Flag = LMDB.db_flags(None)) : Database

Opens and returns the a named Database associated with self. If the database is newly created, it will not be available in other transactions until the transaction that is creating the database commits. If the transaction creating the database aborts, the database is not created.

A database needs to be opened (or created) within a transaction. If a pending transaction for this environment exists, it will be used for this purpose. Otherwise, a new Transaction is created.

If a transaction is created specifically, it will be commited before the Database is returned. Otherwise, no particular action on the existing pending transaction is performed.

Source
database(name : String, flags : Database::Flag = LMDB.db_flags(None), &)

Opens and yields the a named Database associated with self. If the database is newly created, it will not be available in other transactions until the transaction that is creating the database commits. If the transaction creating the database aborts, the database is not created.

A database needs to be opened (or created) within a transaction. If a pending transaction for this environment exists, it will be used for this purpose. Otherwise, a new Transaction is created.

If a transaction is created specifically, it will be commited before the Database is returned. Otherwise, no particular action on the existing pending transaction is performed.

Source
database?(name : String, flags : Database::Flag = LMDB.db_flags(Create))

Opens and returns a named Database associated with self. Create the database if it does not exist.

Source
database?(name : String, flags : Database::Flag = LMDB.db_flags(Create), &)

Opens and yields the a named Database associated with self. Create the database if it does not exist.

Source
do_close

Close the environment and release the memory map when self is disposed (see #close).

Source
drop(db : Database)

Remove the given Database.

Source
dump(to path : String, compact : Bool = false)

Copy the database to another database, at the given path. This may be used to backup an existing environment.

If compact flag is set to true, compaction is performed while copying: free pages are omitted and all pages are sequentially renumbered in output. This option consumes more CPU and runs more slowly than the default.

Source
finalize
Source
flags

Get environment flags.

Source
flags=(flags : Flag)

Set environment flags.

Source
info

Returns raw information about self.

Source
map_size=(size)

Set the memory map size to use for self.

The size should be a multiple of the OS page size. This method may be called if no transactions are active.

Source
max_key_size

Returns the maximum size of keys that can be written.

Source
path

Returns the path to the database environment files.

Source
stat

Returns raw statistics about self.

Source
sync(force : Bool)

Flush the data buffers to disk.

Source
to_unsafe
Source
transaction(on db : Database | Nil = nil, readonly : Bool = false, &)

Create and yields a transaction for use with the environment.

The transaction commits when the block goes out of scope. It is aborted if an exception is raised or if an explicit call to Transaction#abort is made.

Source
transaction(on db : Database | Nil = nil, readonly : Bool = false)

Create a transaction for use with the environment.

Source

Nested types