chickadee » lmdb-ht

lmdb-ht

Documentation

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

Library procedures

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

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

db-close dbprocedure

Closes database handle.

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

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

db-end dbprocedure

Commits and ends transaction.

db-delete dbname keyprocedure

Deletes key from LMDB database.

db-delete-database dbnameprocedure

Deletes LMDB database.

db-ref db keyprocedure

Looks up key in database.

db-set! db key valueprocedure

Sets a key-value pair in the database.

db-count dbprocedure

Returns number of key-value pairs in database.

db-keys dbprocedure

Returns a list of database keys.

db-values dbprocedure

Returns a list of database values.

db-fold f init dbprocedure

Folds over the keys and values in the database.

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

db->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 (db-open fname key: cryptokey)))
  (db-begin mm)
  (let loop ((ks keys) (vs values))
    (if (> (length ks) 0) 
        (begin
          (db-set! mm (string->blob (->string (car ks))) (string->blob (->string (car vs))))
          (loop (cdr ks) (cdr vs)))))
  (db-end mm)
  (db-begin mm)
  (let ((res (let loop ((ks keys) (vs values))
               (if (= (length ks) 0) #t
                   (let ((v (db-ref mm (string->blob (->string (car ks))))))
                     (if (not (equal? (string->blob (->string (car vs))) v))  #f
                         (loop (cdr ks) (cdr vs)))))))
        )
    (db-end mm)
    (db-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.

Repository

https://github.com/iraikov/chicken-lmdb

Version history

3.2
Added db-delete [thanks to alice maz and Caolan McMahon]
3.0
Ported to CHICKEN 5
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 »