Next: LMDB DB-Spec Details, Previous: LMDB Predicates, Up: lib-lmdb [Contents][Index]
This example creates a database, opens it, and add some values to it. Finally the values are read.
| ?- use_module(library(lmdb)). % only needed once per SICStus session. … | ?- lmdb_create(tempdb, [a(+,-)]). | ?- lmdb_open(tempdb, R, [mode(write)]), assertz(tempdb(R)). R = '$lmdb'(4611936272) ? | ?- tempdb(R), lmdb_store(R, a(b,1), T). R = '$lmdb'(4611936272), T = '$db_termref'(0) ? | ?- tempdb(R), lmdb_store(R, a(c,2), T). R = '$lmdb'(4611936272), T = '$db_termref'(1) ? | ?- tempdb(R), lmdb_store(R, a(b,X), T). R = '$lmdb'(4611936272), T = '$db_termref'(2) ? | ?- tempdb(R), lmdb_enumerate(R, Term, _). R = '$lmdb'(4611936272), Term = a(b,1) ? ; R = '$lmdb'(4611936272), Term = a(c,2) ? ; R = '$lmdb'(4611936272), Term = a(b,_A) ? ; | ?- tempdb(R), lmdb_findall(R, Term, Term, ground(Term), Bag). R = '$lmdb'(4611936272), Bag = [a(b,1),a(c,2)] ? | ?- retract(tempdb(R)), lmdb_close(R). R = '$lmdb'(4611936272) ?
Later, in another (or the same) process, the stored data can be read.
| ?- use_module(library(lmdb)). % only needed once per SICStus session. … | ?- lmdb_open(tempdb, R, [mode(read)]), assertz(tempdb(R)). R = '$lmdb'(4560556048) ? | ?- tempdb(R), lmdb_findall(R, Term, Term, ground(Term), Bag). R = '$lmdb'(4560556048), Bag = [a(b,1),a(c,2)] ? | ?- retract(tempdb(R)), lmdb_close(R). R = '$lmdb'(4560556048) ?