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

sqlitekv

v0.1.0

Published

SQLiteKV is a key-value store built on top of SQLite3. This project allows you to perform basic key-value operations with the additional power of SQLite3, making it suitable for applications requiring persistent, lightweight, and reliable storage.

Downloads

15

Readme

SQLiteKV

SQLiteKV is a key-value store built on top of SQLite3. This project allows you to perform basic key-value operations with the additional power of SQLite3, making it suitable for applications requiring persistent, lightweight, and reliable storage.

Features

  • Basic key-value operations: set, get, delete, exists, keys
  • Support for expiry times on keys
  • JSON export of the database
  • Loop operations for repetitive tasks
  • Transaction management
  • Flexible journal modes (WAL, DELETE, etc.)
  • In-memory, temporary, and disk-based storage options
  • Logger mode to track executed SQL queries

Installation

You can install the package by running the following command with npm:

npm install sqlitekv

Or with pnpm:

pnpm install sqlitekv

Usage

Basic Setup

Here is an example of how to set up and use the SQLiteKV store:

import SQLiteKV from "sqlitekv";

(async () => {
    try {
        // Initialize the database with configuration
        const db = new SQLiteKV("example.sqlite", {
            tableName: "example_table",
            autoCommit: true,
            journalMode: "WAL",
            enableLoopOperations: true,
            logQueries: true
        });

        // Perform some operations
        await db.set("key1", "value1");
        const value = await db.get("key1");
        console.log(`Retrieved value for key1: ${value}`);

        // Check if a key exists
        const exists = await db.exists("key1");
        console.log(`Key1 exists: ${exists}`);

        // Delete a key
        await db.delete("key1");
        console.log(`Key1 deleted`);

        // Export the database to JSON
        await db.convertToJson("export.json");
        console.log("Database exported to export.json");
    } catch (error) {
        console.error("Error initializing database:", error);
    }
})();

You can also initialize the database without passing the configuration object:

import SQLiteKV from "sqlitekv";

(async () => {
    try {
        // Initialize the database with default settings
        const db = new SQLiteKV("example.sqlite");

        // Perform some operations
        await db.set("key1", "value1");
        const value = await db.get("key1");
        console.log(`Retrieved value for key1: ${value}`);

        // Check if a key exists
        const exists = await db.exists("key1");
        console.log(`Key1 exists: ${exists}`);

        // Delete a key
        await db.delete("key1");
        console.log(`Key1 deleted`);

        // Export the database to JSON
        await db.convertToJson("export.json");
        console.log("Database exported to export.json");
    } catch (error) {
        console.error("Error initializing database:", error);
    }
})();

Loop Operations

If you need to perform a set of operations repeatedly, you can use the loop operations feature:

const operations = async () => {
    const timestamp = new Date().toISOString();
    await db.set(`test_key_${timestamp}`, `test_value_${timestamp}`);
    console.log(
        `Set key: test_key_${timestamp} with value: test_value_${timestamp}`
    );
};

const iterations = 10;
await db.performLoopOperations(operations, iterations);

Configuration Options

You can customize the behavior of SQLiteKV using the following configuration options:

  • tableName: The name of the table used for storing key-value pairs.
  • autoCommit: Whether to automatically commit transactions.
  • journalMode: The journal mode for SQLite (e.g., WAL, DELETE).
  • sqliteMode: The storage mode for SQLite (disk, memory, temp).
  • logQueries: Whether to log executed SQL queries.
  • enableLoopOperations: Whether to enable loop operations.

Viewing the SQLite Database

You can view and interact with the SQLite database using an online viewer such as SQLite Viewer.

Similar Projects

There is a similar project in Python, which you can check out here: Kvsqlite.

License

This project is licensed under the MIT License.