-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsdb-unit.rkt
42 lines (32 loc) · 1.03 KB
/
fsdb-unit.rkt
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
#lang racket/unit
(require racket/file)
(require "db-sig.rkt")
(import)
(export db^)
(define conn? path-string?)
(define (store dir #:bucket b #:key k #:val v)
(define path (build-path dir b k))
(make-parent-directory* path)
(display-to-file v path #:exists 'replace))
(define (store* dir #:bucket b #:key k #:vals vs)
(define path (build-path dir b k))
(make-parent-directory* path)
(display-lines-to-file vs path #:exists 'replace))
(define (fetch dir #:bucket b #:key k)
(define path (build-path dir b k))
(if (file-exists? path)
(file->string path)
#f))
(define (fetch* dir #:bucket b #:key k)
(define path (build-path dir b k))
(if (file-exists? path)
(file->lines path)
'()))
(define (list-keys dir #:bucket b)
(define path (build-path dir b))
(make-directory* path)
(map path->string (directory-list path)))
(define (append dir #:bucket b #:key k #:val v)
(define path (build-path dir b k))
(make-parent-directory* path)
(display-lines-to-file (list v) path #:exists 'append))