Changeset 33161 in project


Ignore:
Timestamp:
02/06/16 16:46:26 (4 years ago)
Author:
Caolan McMahon
Message:

Updates for v2.0.0 api

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/level

    r31155 r33161  
    11== level
     2
    23[[toc:]]
     4
     5== Description
     6
    37Provides a high-level API to leveldb implementations. Use in combination
    48with an implementation egg (eg, [[https://github.com/caolan/chicken-leveldb|leveldb]]).
    59
     10=== Interface API
    611
    7 === Interface API
    812This module exposes an interface, which other eggs provide implementations
    913of. The API described below is what the interface provides.
    1014
     15==== Basic read and write
    1116
    12 ==== Basic read and write
    13 <enscript highlight="scheme">   
    14 (db-get db key)
    15 </enscript>
     17<procedure>(db-get db key)</procedure>
    1618
    1719Returns the value of {{key}} in {{db}} as a string. Causes an exception if the
    1820key does not exist.
    1921
    20 <enscript highlight="scheme">   
    21 (db-put db key value #!key (sync #f))
    22 </enscript>
     22<procedure>(db-get/default db key default)</procedure>
     23
     24Same as {{db-get}} but returns {{default}} on missing keys instead of raising an exception.
     25
     26<procedure>(db-put db key value #!key (sync #f))</procedure>
    2327
    2428Stores {{value}} under {{key}} in datbase {{db}}. If the sync option can be set to
     
    2731section for more information.
    2832
    29 <enscript highlight="scheme">   
    30 (db-delete db key #!key (sync #f))
    31 </enscript>
     33<procedure>(db-delete db key #!key (sync #f))</procedure>
    3234
    3335Removes the value associated with {{key}} from {{db}}. If the sync option can be
     
    3840
    3941==== Atomic updates (batches)
    40 <enscript highlight="scheme">   
    41 (db-batch db ops #!key (sync #f))
    42 </enscript>
     42
     43<procedure>(db-batch db ops #!key (sync #f))</procedure>
    4344
    4445When making multiple changes that rely on each other you can apply a batch
     
    6566
    6667==== Range queries (streams)
    67 <enscript highlight="scheme">   
    68 (db-stream db #!key start end limit reverse (key #t) (value #t) fillcache)
    69 </enscript>
     68
     69<procedure>(db-stream db #!key start end limit reverse (key #t) (value #t) fillcache)</procedure>
    7070
    7171Allows forward and backward iteration over the keys in alphabetical order.
     
    9191returned as a list but as a string representing the single key or value.
    9292
    93 <enscript highlight="scheme">   
     93<enscript highlight="scheme">
    9494(lazy-map display (db-stream db start: "foo:" end: "foo::" limit: 10)))
    9595</enscript>
     
    111111
    112112==== Synchronous Writes
     113
    113114'''Note:''' this information is mostly copied from the [[http://leveldb.googlecode.com/svn/trunk/doc/index.html|LevelDB docs]]
    114115
     
    137138
    138139=== Creating an interface
     140
    139141If you want to provide your own storage impelmentation, import this egg
    140142and define the interface as follows:
     
    146148  (implementation level-api
    147149
    148     (define (get db key) ...)
    149     (define (put db key value #!key (sync #f)) ...)
    150     (define (delete db key #!key (sync #f)) ...)
    151     (define (batch db ops #!key (sync #f)) ...)
     150    (define (level-get db key) ...)
     151    (define (level-get/default db key) ...)
     152    (define (level-put db key value #!key (sync #f)) ...)
     153    (define (level-delete db key #!key (sync #f)) ...)
     154    (define (level-batch db ops #!key (sync #f)) ...)
    152155
    153     (define (stream db
    154                     #!key
    155                     start
    156                     end
    157                     limit
    158                     reverse
    159                     (key #t)
    160                     (value #t)
    161                     fillcache)
     156    (define (level-stream db
     157                          #!key
     158                          start
     159                          end
     160                          limit
     161                          reverse
     162                          (key #t)
     163                          (value #t)
     164                          fillcache)
    162165      ..)))
    163166</enscript>
     
    165168
    166169=== Implementations
     170
    167171* [[https://github.com/caolan/chicken-leveldb|leveldb]] - provides the {{level}}
    168172  API to libleveldb
     
    170174  API access to another implementation
    171175
     176== Source code / issues
     177
     178[[https://github.com/caolan/chicken-level]]
     179
Note: See TracChangeset for help on using the changeset viewer.