presidium-db
v4.5.0
Published
Presidium DB library
Maintainers
Readme
Presidium DB

Source code: GitHub | License: CFOSS
Presidium DB library.
Installation
with npm:
npm i presidium-dbrequire Presidium DB in CommonJS:
const DiskHashTable = require('presidium-db/DiskHashTable')
const DiskSortedHashTable = require('presidium-db/DiskSortedHashTable')Store data on disk as a hash table
const DiskHashTable = require('presidium-db/DiskHashTable')
const ht = new DiskHashTable({
storageFilepath: '/path/to/storage-file',
headerFilepath: '/path/to/header-file',
initialLength: 1024,
})
await ht.init()
await ht.set('my-key', 'my-value')
const myValue = await ht.get('my-key')
console.log(myValue) // 'my-value'
await ht.delete('my-key')Store data on disk as a sorted hash table
const DiskSortedHashTable = require('presidium-db/DiskSortedHashTable')
const sortedHt = new DiskSortedHashTable({
storageFilepath: '/path/to/storage-file',
headerFilepath: '/path/to/header-file',
initialLength: 1024,
})
await sortedHt.init()
await sortedHt.set('first-key', 'first-value', 1)
await sortedHt.set('second-key', 'second-value', 2)
await sortedHt.set('third-key', 'third-value', 3)
for await (const value of sortedHt.forwardIterator()) {
console.log(value) // first-value
// second-value
// third-value
}
for await (const value of sortedHt.reverseIterator()) {
console.log(value) // third-value
// second-value
// first-value
}
for await (const value of sortedHt.forwardIterator({ startingSortValue: 2, endingSortValue: 3 })) {
console.log(value) // second-value
// third-value
}
for await (const value of sortedHt.reverseIterator({ startingSortValue: 2, endingSortValue: 1 })) {
console.log(value) // second-value
// first-value
}License
Presidium DB is distributed under the CFOSS License.
Support
- minimum Node.js version: 16
Supported Platforms
- Linux
