lmdb-ht

  1. lmdb-ht
  2. Documentation
    1. Library procedures
  3. Examples
  4. About this egg
    1. Author
    2. Repository
    3. Version history
    4. License

Documentation

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

Library procedures

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

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

[procedure] (db-close db)

Closes database handle.

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

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

[procedure] (db-end db)

Commits and ends transaction.

[procedure] (db-delete dbname key)

Deletes key from LMDB database.

[procedure] (db-delete-database dbname)

Deletes LMDB database.

[procedure] (db-ref db key)

Looks up key in database.

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

Sets a key-value pair in the database.

[procedure] (db-count db)

Returns number of key-value pairs in database.

[procedure] (db-keys db)

Returns a list of database keys.

[procedure] (db-values db)

Returns a list of database values.

[procedure] (db-fold f init db)

Folds over the keys and values in the database.

[procedure] (db-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] (db->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 (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.