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

eyal.db

v1.0.0

Published

eyal.db is a high-performance wrapper around better-sqlite3, designed to make database operations faster and easier.

Readme

eyal.db

eyal.db is a high-performance wrapper around better-sqlite3, designed to make database operations faster and easier.


Features

  • 🚀 High Performance: Optimized operations with batching and transactions
  • 🔄 Operation Queue: Intelligent queuing system for optimal database performance
  • 📦 Batch Operations: Insert multiple records efficiently
  • 🛡️ Type Safety: Built with TypeScript for better development experience
  • 💾 SQLite Optimized: Pre-configured SQLite settings for maximum performance

Installation

You can install eyal.db using npm or pnpm:

npm install eyal.db
# OR
pnpm add eyal.db

Quick Start

const { Database } = require("eyal.db");

async function main() {
  const db = new Database("myapp.db");

  // Create a table
  await db.table.create("users", {
    id: 2, // INTEGER
    name: 1, // TEXT
    email: 1, // TEXT
    active: 3, // BOOLEAN
    score: 2, // INTEGER
  });

  // Insert data
  await db.add("users", {
    id: 1,
    name: "John Doe",
    email: "[email protected]",
    active: true,
    score: 100,
  });

  // Query data
  const users = await db.all("users");
  console.log(users);

  // Close connection
  await db.close();
}

main();

API Documentation


Database Constructor

Creates a new database instance.

const { Database } = require("eyal.db");
const db = new Database("database.db"); // Optional filename, defaults to 'eyal.db'

createTable(name, columns)

Creates a new table in the database. Returns a Promise.

Column Types:

  • 1 - TEXT
  • 2 - INTEGER
  • 3 - BOOLEAN (stored as 0/1)
  • 4 - DATE
  • 5 - DATETIME

Example:

await db.table.create("customers", {
  customerName: 1, // TEXT
  customerPaymentMethod: 1, // TEXT
  isPartner: 3, // BOOLEAN
  customerMonthlyPrice: 2, // INTEGER
});

deleteTable(name)

Deletes a table from the database. Returns a Promise.

Example:

await db.table.delete("customers");

add(table, data)

Inserts new data into a table. Returns a Promise.

Example:

await db.add("customers", {
  customerName: "Eyal",
  customerPaymentMethod: "card",
  isPartner: true,
  customerMonthlyPrice: 100,
});

addMany(table, records)

Efficiently inserts multiple records using a transaction. Returns a Promise.

Example:

const users = [
  { name: "Alice", email: "[email protected]", active: true },
  { name: "Bob", email: "[email protected]", active: false },
  { name: "Charlie", email: "[email protected]", active: true },
];

await db.addMany("users", users);

all(table)

Retrieves all rows from a table. Returns a Promise.

Example:

const customers = await db.all("customers");
console.log(customers);

has(table, criteria)

Checks if a record exists in a table. Returns a Promise<boolean>.

Example:

const exists = await db.has("customers", { customerName: "Eyal" });
console.log(exists); // true or false

set(table, data, where)

Updates existing data in a table. Returns a Promise.

Example:

await db.set(
  "customers",
  { customerMonthlyPrice: 200 }, // New data
  { customerName: "Eyal" } // Where condition
);

delete(table, criteria)

Deletes records from a table based on criteria. Returns a Promise.

Example:

await db.delete("customers", {
  customerName: "Eyal",
});

deleteall(table)

Deletes all records from a table. Returns a Promise.

Example:

await db.deleteall("customers");

datasize(table)

Returns the number of records in a table. Returns a Promise<number>.

Example:

const count = await db.datasize("customers");
console.log(`Total customers: ${count}`);

type(table, column)

Returns the type of a specific column. Returns a Promise<string>.

Example:

const columnType = await db.type("customers", "customerMonthlyPrice");
console.log(columnType); // "INTEGER"

transaction(callback)

Executes multiple operations within a transaction for better performance and atomicity. Returns a Promise.

Example:

await db.transaction(() => {
  // Multiple operations that will be executed as a single transaction
  db.add("users", { name: "Alice", email: "[email protected]" });
  db.add("users", { name: "Bob", email: "[email protected]" });
  db.set("users", { active: true }, { name: "Alice" });
});

batch(operations)

Executes multiple operations efficiently in batches. Returns a Promise.

Example:

const operations = [
  () => db.add("users", { name: "User1", email: "[email protected]" }),
  () => db.add("users", { name: "User2", email: "[email protected]" }),
  () => db.set("settings", { value: "enabled" }, { key: "notifications" }),
];

await db.batch(operations);

close()

Closes the database connection. Returns a Promise.

Example:

await db.close();

Advanced Usage

Performance Optimization

eyal.db automatically optimizes your database operations through:

  • Operation Queuing: Batches operations for better performance
  • Statement Caching: Reuses prepared statements
  • Transaction Management: Groups operations when beneficial
  • WAL Mode: Uses Write-Ahead Logging for concurrent access

Error Handling

try {
  await db.add("users", { name: "John", email: "[email protected]" });
} catch (error) {
  console.error("Database operation failed:", error.message);
}

Concurrent Operations

eyal.db handles concurrent operations safely:

// These will be queued and executed efficiently
const promises = [
  db.add("users", { name: "Alice" }),
  db.add("users", { name: "Bob" }),
  db.add("users", { name: "Charlie" }),
];

await Promise.all(promises);

Performance Benchmarks

eyal.db is optimized for speed. Here are some benchmark results:

  • Individual Inserts: ~13ms for 100 records
  • Batch Inserts: ~1ms for 100 records (1200% faster)
  • Concurrent Queries: ~1ms for 50 parallel operations
  • Bulk Operations: ~1ms for 100 transactions

TypeScript Support

eyal.db is built with TypeScript and provides full type definitions:

import { Database } from "eyal.db";

const db = new Database("myapp.db");

interface User {
  id: number;
  name: string;
  email: string;
  active: boolean;
}

const users: User[] = await db.all("users");

Credits