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

  1. Outdated egg!
  2. lmdb
  3. Usage
  4. Documentation
    1. Library procedures
  5. Examples
  6. About this egg
    1. Author
    2. Version history
    3. License

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 [key: enckey] [mapsize: size])

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

[procedure] (lmdb-close db)

Closes database handle.

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

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

[procedure] (lmdb-end db)

Commits and ends transaction.

[procedure] (lmdb-delete-database 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-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 f 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

;; 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.