BDB

Berkeley DB CFFI bindings

Example Usage (Transactions)

CL-USER> (asdf:oos 'asdf:load-op :bdb-playground)
NIL
CL-USER> (in-package :bdb-playground)
#<PACKAGE "BDB-PLAYGROUND">
BDB-PLAYGROUND> (setq *env* (db-env-open "/home/main/tdb" :init-txn t :init-log t :init-lock t :init-mpool t :create t))
#<DB-ENV {B7A4221}>
BDB-PLAYGROUND> (setq *db* (db-open "test.db" :env *env* :auto-commit t :create t))
#<DB-TXN {B8042D1}>
BDB-PLAYGROUND> (with-txn (txn *env*)
		  (db-put *db* 1 "data1" :txn txn)
		  (db-put *db* 2 "data2" :txn txn))
T
BDB-PLAYGROUND> (db-get *db* 1)
"data1"
BDB-PLAYGROUND> (db-get *db* 2)
"data2"
BDB-PLAYGROUND> (db-get *db* 3)
NIL
BDB-PLAYGROUND> (with-txn (txn *env*)
		  (db-put *db* 3 "data3" :txn txn)
		  (db-put *db* 4 "data4" :txn txn)
		  (error "ohoh, abort transaction"))
BDB-PLAYGROUND> (db-get *db* 1)
"data1"
BDB-PLAYGROUND> (db-get *db* 2)
"data2"
BDB-PLAYGROUND> (db-get *db* 3)
NIL
BDB-PLAYGROUND> (db-get *db* 4)
NIL
BDB-PLAYGROUND> (db-del *db* 1)
; Evaluation aborted | comment: if you want to delete an entry, you must use a txn
BDB-PLAYGROUND> (with-txn (txn *env*)
		  (db-del *db* 1 :txn txn))
T
BDB-PLAYGROUND> (db-get *db* 1)
NIL
BDB-PLAYGROUND> (db-get *db* 2)
"data2"
BDB-PLAYGROUND> (db-get *db* 3)
NIL
BDB-PLAYGROUND> (db-get *db* 4)
NIL
BDB-PLAYGROUND> (db-close *db*)
T
BDB-PLAYGROUND> (db-env-close *env*)
NIL
BDB-PLAYGROUND> ;; bye bye
	

Valid XHTML 1.0 Strict