ksql
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

ksql

ksql is a database that stores JS objects, with a synchronous Map-esque interface.

Installing

npm install ksql

API

// js
const {KSQL} = require('ksql');
// ts
import {KSQL} from 'ksql';

Create an instance with new KSQL(name, opts).

name is the name of the database. This is required, and is used to load the DB from disk.

opts is optional, but has this type:

export interface DatabaseOptions<K, V> {
    /** 
     * Set this to a number to tell the DB to cache an object in memory 
     * after it's been retrieved that number of times
     * */
    maxReferences?: number;
    /** Must be an absolute path */
    databaseDir?: string;
    /** Transform data loaded before returning it */
    transform?: (data: any) => V;
    memory?: boolean;
}

Write data into the database with instance.set(key, value). Both key and value can be anything serializable by v8 (basically anything outside of functions).

Read data with instance.get(key) (again, anything serializable).

Lastly, you can batch-read with instance.entries(limit) - which will return an array of [key, value] pairs. The limit param defaults to 100, and will return that many rows at once.

The current benchmark is 0.15ms on average for one read.

Readme

Keywords

Package Sidebar

Install

npm i ksql

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

44.8 kB

Total Files

8

Last publish

Collaborators

  • miaispi