BDB

Berkeley DB CFFI bindings

Example Usage

CL-USER> (asdf:oos 'asdf:load-op :bdb-playground)
NIL
CL-USER> (in-package :bdb-playground)
#<PACKAGE "BDB-PLAYGROUND">
BDB-PLAYGROUND> (setq *db* (db-open "test.db" :create t :exclusive t))
#<DB-STD {AB8B471}>
BDB-PLAYGROUND> (db-put *db* 'key1 "data1")
T
BDB-PLAYGROUND> (db-put *db* 'key2 "data2")
T
BDB-PLAYGROUND> (db-put *db* 'key3 "data3")
T
BDB-PLAYGROUND> (db-put *db* 'key4 "data4")
T
BDB-PLAYGROUND> (db-get *db* 'key2)
"data2"
BDB-PLAYGROUND> (db-get *db* 'key4)
"data4"
BDB-PLAYGROUND> (db-get *db* 'key1022)
NIL
BDB-PLAYGROUND> (db-get *db* 'key1022 :not-found t))
; Evaluation aborted | comment: used debugger to abort, cause of exception...
BDB-PLAYGROUND> (db-get *db* 'key1022 :not-found (lambda () 'uhoh))
UHOH
BDB-PLAYGROUND> (setq *cursor* (db-cursor *db*))
#<BDB::CURSOR {B97D641}>
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY1
"data1"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY2
"data2"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY3
"data3"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY4
"data4"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
NIL
NIL
BDB-PLAYGROUND> (db-cursor-get *cursor* :first t)
KEY1
"data1"
BDB-PLAYGROUND> (db-cursor-get *cursor* :key 'key3 :set t)
KEY3
"data3"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY4
"data4"
BDB-PLAYGROUND> (db-cursor-count *cursor*)  ;;number of duplicates
1
BDB-PLAYGROUND> (db-cursor-close *cursor*)
NIL
BDB-PLAYGROUND> (db-close *db*)
NIL
BDB-PLAYGROUND> (setq *db* (db-open "test.db"))
#<DB-STD {A7EB5E9}>
BDB-PLAYGROUND> (setq *cursor* (db-cursor *db*))
#<BDB::CURSOR {A81DD71}>
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY1
"data1"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY2
"data2"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY3
"data3"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
KEY4
"data4"
BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
NIL
NIL
BDB-PLAYGROUND> (db-cursor-close *cursor*)
NIL
BDB-PLAYGROUND> (db-close *db*)
NIL
BDB-PLAYGROUND> 
	

Valid XHTML 1.0 Strict