npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kvb

v0.0.3

Published

KVBase is a < 3KB key-value store for Bun. It internally uses `bun:sqlite` for the storage.

Downloads

4

Readme

KVBase

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

Installation

bun add kvb

Usage

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

Running Tests

bun wiptest

Benchmarks

cpu: Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
runtime: bun 0.5.0 (x64-darwin)

benchmark         time (avg)             (min … max)       p75       p99      p995
---------------------------------------------------- -----------------------------
• KVBase
---------------------------------------------------- -----------------------------
set             11.4 µs/iter    (6.83 µs … 32.14 ms)   8.57 µs  21.29 µs  30.91 µs
get (first)     1.28 µs/iter   (958.38 ns … 1.97 µs)   1.38 µs   1.97 µs   1.97 µs
get (all)       2.03 µs/iter     (1.39 µs … 4.61 µs)   2.23 µs   4.61 µs   4.61 µs
delete          4.16 µs/iter     (3.55 µs … 5.59 µs)   4.41 µs   5.59 µs   5.59 µs
update          6.02 µs/iter    (4.29 µs … 11.21 µs)   6.51 µs  11.21 µs  11.21 µs
set (schema)  684.69 µs/iter   (386.83 µs … 7.35 ms) 637.98 µs   4.07 ms   4.93 ms

summary for KVBase
  set
   8.9x slower than get (first)
   5.63x slower than get (all)
   2.74x slower than delete
   1.89x slower than update
   60.08x faster than set (schema)

To run the benchmarks, use the following command:

bun run index.bench.ts

API

new KVBase(options: KVBaseOptions)

Creates a new instance of KVBase.

options

Type: KVBaseOptions Source: src/index.ts

Schema for KVBaseOptions.

Schema is an optional parameter. If not supplied, No schema will be used. If supplied, the schema will be used to validate the data in every set call. If the data is invalid, an error will be thrown. The schema is validated using fastest-validator and the schema is passed as it is to the validator. For more information on the schema, refer to the fastest-validator documentation. Supply the Validator instance options in the options.validatorOptions property.

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.