Jsonjsdb - Client-side Relational Database

0.8.10 · active · verified Wed Apr 22

Jsonjsdb is a client-side relational database library specifically designed for static Single Page Applications. It enables offline data storage and querying capabilities, functioning effectively whether the application is run locally via the `file://` protocol or served over HTTP/HTTPS (e.g., localhost or production servers). The current stable JavaScript version is 0.8.10, with the project showing a somewhat active release cadence, although many recent updates have focused on its Python counterpart. A key differentiator is its unique approach to handling database file extensions (`.json.js` for `file://` and `.json` for `http(s)://`) based on the protocol, and its reliance on HTML-embedded configuration, which distinguishes it from more traditional pure JavaScript database solutions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate `Jsonjsdb`, initialize it asynchronously, and then perform basic data retrieval operations like getting all records from a table and retrieving a specific record by ID.

import Jsonjsdb from 'jsonjsdb';

async function initializeAndQueryDb() {
  const db = new Jsonjsdb();
  try {
    // Initialize the database. This reads the __table__.json(.js) and table data.
    await db.init();

    // Example: Get all entries from a 'user' table
    const users = db.getAll('user');
    console.log('All users:', users);

    // Example: Get a specific user by ID (assuming 'user' table has IDs like 123)
    const specificUser = db.get('user', 123);
    console.log('Specific user (ID 123):', specificUser);

    // You can also demonstrate iteration or checking existence
    db.foreach('product', (product) => {
      console.log('Product found:', product.name);
    });

    if (db.exists('settings', 'app_name')) {
      console.log('App name setting exists.');
    }

  } catch (error) {
    console.error('Failed to initialize or query database:', error);
    // Depending on the error, provide user guidance. E.g., check 'db' folder, config.
  }
}

initializeAndQueryDb();

view raw JSON →