chickadee » lmdb

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

lmdb

Usage

(require-extension lmdb)

Documentation

The lmdb library provides bindings for the Lightning Memory-Mapped Database Manager (LMDB) database management library.

Library procedures

(lmdb-open dbname [key: enckey] [mapsize: size])procedure

Opens or creates LMDB database with optional encryption key and map size, and returns database environment handle.

lmdb-close dbprocedure

Closes database handle.

(lmdb-begin db [dbname: dbname])procedure

Begins LMDB transaction with optional database name. This is required for all operations.

lmdb-end dbprocedure

Commits and ends transaction.

lmdb-delete-database dbnameprocedure

Deletes LMDB database.

lmdb-ref db keyprocedure

Looks up key in database.

lmdb-set! db key valueprocedure

Sets a key-value pair in the database.

lmdb-count dbprocedure

Returns number of key-value pairs in database.

lmdb-keys dbprocedure

Returns a list of database keys.

lmdb-values dbprocedure

Returns a list of database values.

lmdb-fold f init dbprocedure

Folds over the keys and values in the database.

lmdb-for-each f dbprocedure

Iterates over the keys and values in the database.

hash-table->lmdb t dbfile #!optional enckeyprocedure

Saves SRFI-69 hash table to database.

lmdb->table dbfile #!optional enckeyprocedure

Loads database into SRFI-69 hash table.

Examples

;; lmdb encrypted key-value creation and lookup

(let* ((fname (make-pathname "." "mydb.mdb"))
       (keys (list "k1" 'k2 '(k3)))
       (values (list 'one 2 "three"))
       (cryptokey (string->blob "1234"))
       (mm (lmdb-open fname key: cryptokey)))
  (lmdb-begin mm)
  (let loop ((ks keys) (vs values))
    (if (> (length ks) 0) 
        (begin
          (lmdb-set! mm (string->blob (->string (car ks))) (string->blob (->string (car vs))))
          (loop (cdr ks) (cdr vs)))))
  (lmdb-end mm)
  (lmdb-begin mm)
  (let ((res (let loop ((ks keys) (vs values))
               (if (= (length ks) 0) #t
                   (let ((v (lmdb-ref mm (string->blob (->string (car ks))))))
                     (if (not (equal? (string->blob (->string (car vs))) v))  #f
                         (loop (cdr ks) (cdr vs)))))))
        )
    (lmdb-end mm)
    (lmdb-close mm)
    res)
  )

About this egg

Author

Based on the lmdb library from LambdaNative - a cross-platform Scheme framework. Copyright (c) 2009-2015, University of British Columbia All rights reserved.

Packaged for Chicken by Ivan Raikov and Caolan McMahon.

Version history

2.3
Using (exn lmdb ...) style composite conditions to signal lmdb exceptions [thanks to Caolan McMahon].
2.0
Added lmdb-begin/end procedures for explicit transaction control.
1.0
Initial release

License

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

  Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

  Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

  Neither the name of the author nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

Contents »