rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/test_lmdb.sc -rw-r--r-- 825 bytes View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months ago
                                                                                
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
let db = (import ..tukan.db)

inline dbcall (f ...)
    try (f ...)
    except (err)
        'handle err

let mapname = (.. module-dir "/test_lmdb_tmp.db")

let env = (dbcall db.Environment)
dbcall 'open env mapname db.NoSubDir

local key = (db.Value 123)

try
    do  # write
        let txn = ('begin env)
        let dbi = ('open txn db.Create)
        'put txn dbi key (db.Value 456)
        'commit txn
    do  # read
        let txn = ('begin env db.ReadOnly)
        let dbi = ('open txn)
        let val = ('get txn dbi key)
        assert (val as i32 == 456)
        'commit txn
    do  # delete
        let txn = ('begin env)
        let dbi = ('open txn)
        let val = ('get txn dbi key)
        assert (val as i32 == 456)
        'del txn dbi key
        'commit txn
except (err)
    'handle err

'close env