Skip to content

LiloLookup/kvb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KVBase

KVBase is a lightweight key-value store for Bun. It internally uses bun:sqlite for the storage.

Lilo's Modification

Lilo is a quick Minecraft server lookup and statistics provider and as such a service relies on performance and stability, we've decided to switch over to bun and use this modified kvb fork as a easy to use and maintain database.

But what does this fork modify?
Well, it mainly modifies the syntax in order to keep it very similar to node-redis & to expand kvb's capabilities.

Thank you gaurishhs for providing the base of kvb ❤️

Installation

git submodule add https://github.com/LiloLookup/kvb

Usage

Warning: Usage might modify over the next time without a proper documentation. We will promise to update the documentation once we're comfortable about the end-result.

import {KVBase} from 'kvb';

const db = new KVBase();

await db.set('foo', 'bar');
await db.get('foo'); // bar
await db.delete('foo');
await db.update('foo', 'bar');

Note: If no options.bunOptions.filename is given, Memory Storage will be used.

Typescript Support

KVBase is written in Typescript and has full types support.

Use Typescript Generics while creating a new instance of KVBase to get the correct types.

import {KVBase} from 'kvb';

const db = new KVBase<string>();

await db.set('foo', 'bar');
await db.get('foo'); // bar

API

new KVBase(options: KVBaseOptions)

Creates a new instance of KVBase.

options

Type: KVBaseOptions Source: src/index.ts

interface KVBaseOptions {
    /**
     * Bun options given to the bun:sqlite instance.
     */
    bunOptions?: {
        filename?: string;
        options?: number | { readonly?: boolean; create?: boolean; readwrite?: boolean; }
    };
    /**
     * The name of the table to use.
     * @Default 'kvbase'
     */
    tableName?: string;
}

db.set(key: string, value: any)

Sets a key-value pair in the database.

db.get(key: string)

Gets a value from the database.

db.delete(key: string)

Deletes a key-value pair from the database.

db.update(key: string, value: any)

Updates a key-value pair in the database.

db.close()

Close the database connection.

License

MIT © Gaurish Sethia. See LICENSE for more details.

About

kvb but optimized for Lilo's use cases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%