Previous: , Up: LMDB Predicates   [Contents][Index]


10.25.5.3 The Predicates

lmdb_create(+Path, +SpecList)
lmdb_create(+Path, +SpecList, +Options)

Creates a brand new LMDB database with the given spec list. Path should be a file system path where a new directory can be created. If some file or directory already exists there, an exception is raised.

lmdb_open(+Path, -DBRef)
lmdb_open(+Path, -DBRef, +Options)

Opens an existing database and unifies DBRef with its reference. Path should be a file system path to the directory that holds the database.

Please note: Only one DBRef may be connected to the same Path at the same time in the same process. I.e., you must not call lmdb_open/2 twice with the same Path without closing the DBRef before the second call.

lmdb_with_db(+Path, :Goal)
lmdb_with_db(+Path, :Goal, +Options)

Opens an existing database, calls Goal with its reference, as if by call(Goal, DBRef), and ensures that the database is closed afterwards. Goal may backtrack and succeed multiple times. Path should be a file system path to the directory that holds the database.

Please note: see lmdb_open/2 for restrictions on opening the same Path more than once at the same time.

lmdb_close(+DBRef)

Closes the database referenced by DBRef.

lmdb_store(+DBRef, +Term, -TermRef)

Stores Term in the database DBRef. TermRef is unified with a corresponding term reference. The functor of Term must match the functor of a spec in the db-spec associated with DBRef.

lmdb_fetch(+DBRef, ?Term, ?TermRef)

Unifies Term with a term from the database DBRef. At the same time, TermRef is unified with a corresponding term reference. Backtracking over the predicate unifies with all terms matching Term.

If TermRef is not instantiated, both the functor and the instantiatedness of Term must match a spec in the db-spec associated with DBRef.

If TermRef is instantiated, the referenced term is read and unified with Term.

If you simply want to find all matching terms, it is more efficient to use lmdb_findall/5 or lmdb_enumerate/3.

lmdb_erase(+DBRef, +TermRef)

Deletes the term from the database DBRef that is referenced by TermRef.

lmdb_enumerate(+DBRef, ?Term, -TermRef)

Unifies Term with a term from the database DBRef. At the same time, TermRef is unified with a corresponding term reference. Backtracking over the predicate unifies with all terms matching Term.

Implemented by linear search—the db-spec associated with DBRef is ignored.

lmdb_findall(+DBRef, +Template, +Term, :Goal, -Bag)

Unifies Bag with the list of instances of Template in all proofs of Goal found when Term is unified with a matching term from the database DBRef. Both the functor and the instantiatedness of Term must match a spec in the db-spec associated with DBRef. Conceptually, this predicate is equivalent to findall(Template, (lmdb_fetch(DBRef, Term, _), Goal), Bag).

lmdb_compress(+DBRefFrom, +DBRefTo)

Copies the database given by DBRefFrom to a new database given by DBRefTo. The new database will be a compressed version of the first one in the sense that it will not have “holes” resulting from deletion of terms. Deleted term references will also be reused, which implies that references that refer to terms in the old database will be invalid in the new one.

The terms of DBRefFrom will be appended to any existing terms of DBRefTo. Of course, DBRefTo must have an indexing specification that enables the terms in DBRefFrom to be inserted into it.

lmdb_sync(+DBRef)

Flushes any cached information from the database referenced by DBRef to stable storage.

lmdb_make_iterator(+DBRef, +Term, -Iterator)

Creates a new iterator and unifies it with Iterator. The iterator iterates through the terms that would be found by lmdb_fetch(DBRef, Term, _).

Every iterator created by lmdb_make_iterator/3 must be destroyed with lmdb_iterator_done/1.

lmdb_with_iterator(+DBRef, +Term, :Goal)

Creates a new iterator, calls Goal with it, as if by call(Goal, Iterator), and ensures that the iterator is destroyed afterwards. Goal may backtrack and succeed multiple times. See the documentation of lmdb_make_iterator/3.

lmdb_iterator_next(+Iterator, -Term, -TermRef)

Iterator advances to the next term, and Term and TermRef are unified with the term and its reference pointed to by Iterator. If there is no next term, the predicate fails.

lmdb_iterator_done(+Iterator)

Deallocates Iterator, which must not be in use anymore.

lmdb_property(+DBRef, -Property)

Unifies Property with one of the properties of the database given by DBRef, which are:

path(P)

The file system path of the database.

speclist(L)

The SpecList with which the database was created.

mapsize(S)

The mapsize, or size limit, of the database.

mode(S)

The access mode with which the database was opened. One of the atoms read and write.

Enumerates all four properties on backtracking.

lmdb_export(+DBRef, +ExportFile)

Exports the database given by DBRef to the text file ExportFile. ExportFile can be imported by lmdb_import/2.

lmdb_import(+DBRef, +ImportFile)

Imports the text file ImportFile into the database given by DBRef.

The ImportFile should have been written by lmdb_export/2 or by the corresponding functionality in library(bdb).



Send feedback on this subject.