new Database

Create a new database or recover from an exist database.

new Database(dbpath: string, options:DatabaseOptions):Database

Example

import { Database } from 'rippledb'
const db = new Database('/path/to/db', {
debug: true
});

dbpath

The folder path for Database data dir. It can be either an absolute path like /data/db or relative path like ./db.

DatabaseOptions

FieldTypeDefaultDescription
debugbooleanfalse
comparatorComparatorComparator
writeBufferSizenumber4194304Default is 4MB
maxFileSizenumber2097152Default is 2MB
maxOpenFilesnumber1000
blockCacheLRUCache<Buffer, Block>new Cache<Buffer, Block>({max: 2048})
blockSizenumber4096Default is 4KB
blockRestartIntervalnumber16
reuseLogsbooleanfalse
filterPolicyFilterPolicynew BloomFilter()FilterPolicy
lockfileStalenumber10000Default is 10s
infoLogFileHandle|nullFileHandle
log(message: string) => Promise<void>(msg) => this.infoLog.appendFile(msg)

FilterPolicy

interface FilterPolicy {
name(): string;
keyMayMatch(key: Slice, filter: Slice): boolean;
}