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 🙏

© 2025 – Pkg Stats / Ryan Hefner

deepbase-sqlite

v3.2.0

Published

⚡ DeepBase SQLite - SQLite database driver

Readme

deepbase-sqlite

SQLite driver for DeepBase.

Installation

npm install deepbase deepbase-sqlite

Description

Stores data in SQLite database files. Perfect for:

  • ✅ Production applications
  • ✅ Medium to large datasets
  • ✅ Fast queries and transactions
  • ✅ ACID compliance
  • ✅ Embedded database solution
  • ✅ Zero configuration needed

Usage

import DeepBase from 'deepbase';
import SqliteDriver from 'deepbase-sqlite';

const db = new DeepBase(new SqliteDriver({
  path: './data',
  name: 'mydb'
}));

await db.connect();

await db.set('users', 'alice', { name: 'Alice', age: 30 });
const alice = await db.get('users', 'alice');

Options

new SqliteDriver({
  path: './data',              // Directory to store database files
  name: 'default',            // Database filename (without .db)
  nidAlphabet: 'ABC...',      // Alphabet for ID generation
  nidLength: 10               // Length of generated IDs
})

Features

High Performance

Uses better-sqlite3 for synchronous operations wrapped in async API:

  • Prepared statements for optimal performance
  • Transaction support for batch operations
  • Fast lookups with indexed keys

Singleton Pattern

Multiple instances pointing to the same database file will share the same connection:

const db1 = new DeepBase(new SqliteDriver({ name: 'mydb' }));
const db2 = new DeepBase(new SqliteDriver({ name: 'mydb' }));
// Both use the same underlying database connection

Nested Data Structure

Efficiently stores nested objects using a key-value schema:

  • Keys are stored as dot-notation paths (e.g., user.profile.name)
  • Values are stored as JSON
  • Fast lookups for both exact keys and partial paths

ACID Compliance

SQLite provides:

  • Atomicity: All operations complete or none do
  • Consistency: Data remains valid across transactions
  • Isolation: Concurrent operations don't interfere
  • Durability: Committed data persists even after crashes

Database Structure

Data is stored in a simple key-value table:

CREATE TABLE deepbase (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL
)

Example data:

key                    | value
-----------------------|------------------
users.alice.name       | "Alice"
users.alice.age        | 30
users.bob.name         | "Bob"
users.bob.age          | 25
config.theme           | "dark"
config.lang            | "en"

Use Cases

  • Production Apps: Reliable embedded database for web/desktop apps
  • Medium Datasets: Handles millions of records efficiently
  • Offline First: Works without network or external database server
  • Desktop Apps: Perfect for Electron or Tauri applications
  • Mobile Apps: Lightweight database for React Native/Capacitor
  • IoT Devices: Embedded storage for edge computing
  • Serverless: Deploy with your functions, no external DB needed

Performance

SQLite offers excellent performance:

  • Fast reads and writes with prepared statements
  • Efficient indexing for quick lookups
  • Transaction batching for bulk operations
  • Low memory footprint

Migration

Easy to migrate between SQLite and other drivers:

import DeepBase from 'deepbase';
import SqliteDriver from 'deepbase-sqlite';
import MongoDriver from 'deepbase-mongodb';

const db = new DeepBase([
  new SqliteDriver({ path: './data' }),
  new MongoDriver({ url: 'mongodb://localhost:27017' })
]);

await db.connect();
await db.migrate(0, 1); // Migrate SQLite to MongoDB

File Structure

Data is stored as SQLite database files:

data/
  mydb.db
  users.db
  config.db

Comparison with JSON Driver

| Feature | SQLite | JSON | |---------|--------|------| | Performance | ⚡ Very Fast | 🐌 Slower for large data | | File Size | 📦 Compact | 📄 Human readable | | Transactions | ✅ ACID | ❌ No transactions | | Query Speed | 🚀 Indexed | 🔍 Full scan | | Reliability | 💪 Very High | ⚠️ File corruption risk | | Debugging | 🔧 SQL tools | 👁️ Easy to inspect |

Best Practices

Use Transactions for Bulk Operations

// Better: Use root object set for bulk inserts
const data = {
  user1: { name: 'Alice' },
  user2: { name: 'Bob' },
  user3: { name: 'Charlie' }
};
await db.set('users', data);

Disconnect Properly

// Always disconnect to close database connection
await db.disconnect();

Use Appropriate Paths

// Good: Organize data hierarchically
await db.set('users', userId, 'profile', data);

// Avoid: Flat structure loses benefits of nesting
await db.set(`user_${userId}_profile`, data);

License

MIT - Copyright (c) Martin Clasen