You are looking at historical revision 33141 of this page. It may differ significantly from its current revision.

lmdb

Usage

(require-extension lmdb)

Documentation

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

Library procedures

[procedure] (lmdb-open dbname [enckey])

Opens or creates LMDB database with optional encryption key.

[procedure] (lmdb-delete dbname)

Deletes LMDB database.

[procedure] (lmdb-ref db key)

Looks up key in database.

[procedure] (lmdb-set! db key value)

Sets a key-value pair in the database.

[procedure] (lmdb-close db)

Closes database handle.

[procedure] (lmdb-count db)

Returns number of key-value pairs in database.

[procedure] (lmdb-keys db)

Returns a list of database keys.

[procedure] (lmdb-values db)

Returns a list of database values.

[procedure] (lmdb-fold f init db)

Folds over the keys and values in the database.

[procedure] (lmdb-for-each db)

Iterates over the keys and values in the database.

[procedure] (hash-table->lmdb t dbfile [enckey])

Saves SRFI-69 hash table to database.

[procedure] (lmdb->table dbfile [enckey])

Loads database into SRFI-69 hash table.

Examples

(let* ((fname (make-pathname "." "test.mdb"))
       (keys (list "k1" 'k2 '(k3)))
       (values (list 'one 2 "three"))
       (mm (lmdb-open fname))
    (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-close mm)
               (let* ((mm (lmdb-open fname))
                       (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-close mm)
                  (lmdb-delete fname)
                  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.

Version history

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.