MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

design lmdb api

+69 -1
+59
examples/spec/lmdb.js
··· 1 + import { test, summary } from './helpers.js'; 2 + import lmdb from 'ant:lmdb'; 3 + import fs from 'ant:fs'; 4 + 5 + console.log('LMDB Tests\n'); 6 + 7 + const dbPath = `ant-spec-lmdb-${Date.now()}-${Math.floor(Math.random() * 1e6)}.mdb`; 8 + 9 + test('lmdb.version is string', typeof lmdb.version, 'string'); 10 + test('lmdb.open exists', typeof lmdb.open, 'function'); 11 + test('lmdb.constants exists', typeof lmdb.constants, 'object'); 12 + 13 + const env = lmdb.open(dbPath, { 14 + noSubdir: true, 15 + mapSize: 4 * 1024 * 1024, 16 + maxDbs: 8 17 + }); 18 + test('env open', typeof env.openDB, 'function'); 19 + 20 + const db = env.openDB('main', { create: true }); 21 + test('db open', typeof db.get, 'function'); 22 + 23 + db.put('hello', 'world'); 24 + test('db.get string', db.get('hello', { as: 'string' }), 'world'); 25 + 26 + const bytesIn = new Uint8Array([1, 2, 3, 255]); 27 + db.put('bytes', bytesIn); 28 + const bytesOut = db.get('bytes'); 29 + test('db.get bytes is Uint8Array', bytesOut instanceof Uint8Array, true); 30 + test('db.get bytes length', bytesOut.length, 4); 31 + test('db.get bytes[3]', bytesOut[3], 255); 32 + 33 + const tx = env.beginTxn(); 34 + tx.put(db, 'tx-key', 'tx-value'); 35 + tx.commit(); 36 + test('txn commit', db.get('tx-key', { as: 'string' }), 'tx-value'); 37 + 38 + const ro = env.beginTxn({ readOnly: true }); 39 + test('ro txn read', ro.get(db, 'tx-key', { as: 'string' }), 'tx-value'); 40 + ro.abort(); 41 + 42 + test('db.del returns true', db.del('hello'), true); 43 + test('db.get missing returns undefined', db.get('hello'), undefined); 44 + 45 + const stat = env.stat(); 46 + const info = env.info(); 47 + test('env.stat entries number', typeof stat.entries, 'number'); 48 + test('env.info mapSize number', typeof info.mapSize, 'number'); 49 + 50 + db.close(); 51 + env.close(); 52 + 53 + if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath); 54 + if (fs.existsSync(`${dbPath}-lock`)) fs.unlinkSync(`${dbPath}-lock`); 55 + 56 + test('db file cleaned up', fs.existsSync(dbPath), false); 57 + test('db lock file cleaned up', fs.existsSync(`${dbPath}-lock`), false); 58 + 59 + summary();
+9
include/modules/lmdb.h
··· 1 + #ifndef ANT_LMDB_MODULE_H 2 + #define ANT_LMDB_MODULE_H 3 + 4 + #include "types.h" 5 + 6 + jsval_t lmdb_library(struct js *js); 7 + void cleanup_lmdb_module(void); 8 + 9 + #endif
+1 -1
meson/deps/meson.build
··· 211 211 llhttp, pcre2_dep, libuv_dep, base64_dep, 212 212 argtable3_dep, tlsuv_dep, libsodium_dep, 213 213 yyjson_dep, minicoro_dep, uuidv7_dep, 214 - openssl_dep, zlib_dep, uthash_dep, 214 + openssl_dep, zlib_dep, uthash_dep, lmdb_dep, 215 215 ] + mbedtls_dep + win_deps 216 216 217 217 if host_machine.system() == 'darwin'