aboutsummaryrefslogtreecommitdiff
path: root/scratch.scm
blob: add804b4a296ac8edcd7cd917099da934882ac4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(use-modules (leveldb)
             (cas)
             (srfi srfi-167)
             (rnrs bytevectors))


;; Open db with leveldb directly to create db (requires set-create-if-missing flag)
;; We cannot pass config to okvs-open yet.

(define leveldb-options
  (leveldb-options-create))

(leveldb-options-set-create-if-missing
 leveldb-options 1)

(define db
  (leveldb-open "./data/" leveldb-options))

(leveldb-close db)

;; Use the okvs interface

(define okvs
  (make-leveldb-okvs))

(okvs-open okvs "./data")

(okvs-set! okvs
           (make-bytevector 1 1)
           (string->utf8 "hello "))

(leveldb-put db
             (make-bytevector 1 2)
             (string->utf8 "world"))
(display
 (utf8->string
  (okvs-ref okvs (make-bytevector 1 1))))

(display
 (utf8->string
  (okvs-ref okvs (make-bytevector 1 2))))


;; Create a Content-addressable storage
(define cas
  (make-cas okvs))

;; Store a string in the cas and get the key
(define key
  (cas-put! cas (string->utf8 "Hello World!")))

;; the content can now be accessed by its key (which is also it's hash)
(display key)

;; Retrieve contetn
(utf8->string (cas-get cas key))

(okvs-close okvs)