9.1
Keystore
| (require keystore) |
A small persistent key–value store backed by SQLite. Keys and values may be arbitrary Racket values and are stored using transparent serialization.
1 Overview
The keystore provides persistent storage with automatic serialization and deserialization. Keys are additionally stored in a stringified lowercase form, which allows glob-style queries.
2 Structure
struct
(struct keystore (file path dbh))
file : any/c path : path? dbh : any/c
Represents an open keystore. The file field contains the
original argument, path is the resolved database path, and
dbh is the SQLite connection.
3 Opening
Opens or creates a keystore. When file is a symbol, a cache
location is used; otherwise it is interpreted as a filesystem path.
The database schema is created automatically if it does not yet exist.
4 Basic Operations
Stores value under key, replacing any existing value.
The function always returns #t.
Retrieves the value associated with key. If the key is not
present, the provided default value is returned when given; otherwise
the symbol 'ks-nil is returned.
Returns #t if the key exists, and #f otherwise.
Removes the key from the store. The function always returns #t.
5 Enumeration
Returns all keys in the store.
Returns all key–value pairs as cons cells.
6 Glob Queries
Glob queries operate on a lowercase string representation of keys.
Returns all keys whose string form matches pattern.
procedure
(ks-key-values-glob ks pattern) → (listof (cons/c any/c any/c))
ks : keystore? pattern : string?
Returns key–value pairs whose keys match pattern.
7 Raw Access
Returns raw key rows in the form:
(list key-string str-key)
Returns raw key–value rows in the form:
(list key-string str-key value-string)
8 Examples
8.1 Basic Usage
(define ks (ks-open 'demo)) (ks-set! ks 'a 42) (ks-set! ks "b" '(1 2 3)) (ks-get ks 'a) (ks-get ks 'missing) (ks-get ks 'missing 0)
8.2 Enumeration
(ks-keys ks) (ks-key-values ks)
8.3 Glob Query Example
(ks-keys-glob ks "*b*")