Berkley DB CFFI-Bindings

Secondary Databases 

Notes: the C library handles secondaries like this: db_create: - will create environment, if none specified and add to db pointer db_put/__db_put: - create cursor with write-lock - use __db_c_put on cursor to insert data __db_c_put: - uses private flag DB_UPDATE_SECONDARY to do puts on secondary databases - use __db_s_first and __db_s_next for iterating over secondaries, they will take care of thread-locking - in first loop add new keys: - call callback to get secondary key - open cursor on secondary with transaction and lock id of primary database - use __db_c_put with DB_UPDATE_SECONDARY flag to insert data into secondary - close cursor - in second loop remove old secondary indicies: - get old secondary key - if secondary key needs to be deleted than: - get cursor - use get to move cursor to position - delete entry - update primary database now perl/tcl/python/ruby libs weren't much more helpfull :( for the lisp library: - when opening a database it depends on the environment, wether we'll use the C-based implementation or a transaction based. If transactions are supported by environment. Todo so, db-open returns different kind of classes: - db-std ;; standard db-class, if txn not allowed - db-txn ;; if environment supports transactions - db-associate needs different implementations for db-std and db-txn: - db-std: - use the old low level method - use defcallback and go on - no changes to db-put - db-txn: - add callback function and secondary to table in database instance - when closing secondary, remove from table - don't use defcallback, use lambda directly - overwrite db-put: - create an transaction - add data to primary - in a loop, add keys to secondaries

(defcstruct DBT ;;tried to avoid using DBT directly... :'(
  (data :pointer)
  (size :uint32)
  (ulen :uint32)
  (dlen :uint32)
  (doff :uint32)
  (flags :uint32))