Keystore Class
keystore%
new
close
handle
set!
get
drop!
exists?
count
glob
glob-kv
keys-glob
keys
key-values
with-lock
1 Examples
1.1 Basic Usage
1.2 Nested Calls
1.3 Glob Queries
1.4 Locking
9.3

Keystore Class🔗ℹ

 (require keystore/class) package: keystore

An object-oriented wrapper around keystore. It provides a small class interface to the persistent key-value store.

class

keystore% : class?

  superclass: object%

A keystore class backed by SQLite.

constructor

(new keystore% [file file])  (is-a?/c keystore%)

  file : (or/c path? string? symbol?)
Opens or creates a keystore using file. The meaning of file is the same as for ks-open.

method

(send a-keystore close)  boolean?

Closes the keystore connection.

method

(send a-keystore handle)  keystore?

Returns the underlying keystore handle.

method

(send a-keystore set! key value)  (is-a?/c keystore%)

  key : any/c
  value : any/c
Stores value under key. Returns the object itself, so method calls may be nested.

method

(send a-keystore get key default ...)  any/c

  key : any/c
  default : any/c
Retrieves the value associated with key. If no value is found, the optional default is returned; otherwise 'ks-nil is returned.

method

(send a-keystore drop! key)  (is-a?/c keystore%)

  key : any/c
Removes key from the store and returns the object itself.

method

(send a-keystore exists? key)  boolean?

  key : any/c
Returns #t if key exists, and #f otherwise.

method

(send a-keystore count)  number?

Returns the number of keys in the keystore.

method

(send a-keystore glob pattern)  (listof any/c)

  pattern : string?
Returns keys matching pattern.

method

(send a-keystore glob-kv pattern)

  (listof (cons/c any/c any/c))
  pattern : string?
Returns key=value pairs matching pattern.

method

(send a-keystore keys-glob pattern)  (listof any/c)

  pattern : string?
Alias for glob.

method

(send a-keystore keys)  (listof any/c)

Returns all keys.

method

(send a-keystore key-values)  (listof (cons/c any/c any/c))

Returns all key-value pairs.

method

(send a-keystore with-lock proc)  any/c

  proc : (-> any/c)
Calls proc while holding the lock belonging to this keystore object and returns the value produced by proc. Other threads using with-lock on the same object wait until the lock is released.

The lock is reentrant for nested calls on the same thread and is released when control leaves proc, including when an exception is raised. Keystore methods do not acquire this lock automatically.

1 Examples🔗ℹ

1.1 Basic Usage🔗ℹ

(define ks (new keystore% [file 'demo]))
 
(send ks set! 'a 42)
(send ks set! "b" '(1 2 3))
 
(send ks get 'a)
(send ks get 'missing)
(send ks get 'missing 0)

1.2 Nested Calls🔗ℹ

(define ks (new keystore% [file 'demo]))
 
(send (send (send ks set! 'a 1)
            set! 'b 2)
      drop! 'a)

1.3 Glob Queries🔗ℹ

(send ks glob "*b*")
(send ks glob-kv "*b*")

1.4 Locking🔗ℹ

(send ks with-lock
      (λ ()
        (send ks set! 'counter
              (add1 (send ks get 'counter 0)))))