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

@rinari/bun-sqlite

v1.0.0

Published

Bun-native SQLite driver for @rinari/orm using bun:sqlite

Readme

@rinari/bun-sqlite

High-performance Bun-native SQLite driver for Rinari ORM using bun:sqlite.

Features

  • Bun-native performance - Built on Bun's native bun:sqlite module
  • 3-6x faster than better-sqlite3 for read queries
  • Synchronous API - No async/await needed
  • Multi-database support - Manage multiple SQLite files
  • ACID transactions - Automatic rollback on errors
  • Advanced query operators - $gt, $lt, $in, $like, $between, etc.
  • Index management - Create and drop indexes
  • WAL mode - Write-Ahead Logging for better concurrency
  • Comprehensive aggregations - SUM, AVG, MIN, MAX, COUNT

Requirements

  • Bun runtime (>=1.0.0)
  • This driver only works with Bun, not Node.js

Installation

bun add @rinari/bun-sqlite @rinari/orm @rinari/types

Quick Start

import { BunSQLiteDriver } from '@rinari/bun-sqlite';
import { ORM } from '@rinari/orm';
import { DataTypes } from '@rinari/types';

// Initialize driver
const driver = new BunSQLiteDriver({
  storageDir: './data',
});

// Create ORM instance
const orm = new ORM({ driver });

// Define a model
const User = orm.define('default', 'users', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  username: { type: DataTypes.TEXT, notNull: true, unique: true },
  email: { type: DataTypes.TEXT, notNull: true },
  age: { type: DataTypes.INTEGER },
});

// Use it!
const alice = User.create({
  username: 'alice',
  email: '[email protected]',
  age: 25,
});

const adults = User.findAll({
  where: { age: { $gte: 18 } },
});

// Cleanup
orm.disconnect();

Why Bun SQLite?

Bun's native SQLite implementation is significantly faster than better-sqlite3:

  • 3-6x faster for read queries
  • 8-9x faster than deno.land/x/sqlite
  • Native integration with Bun runtime
  • Zero external dependencies

Performance Comparison

Based on the Northwind Traders dataset:

| Operation | better-sqlite3 | bun:sqlite | Speedup | | -------------- | -------------- | ---------- | ------- | | SELECT queries | 100ms | 20-30ms | 3-5x | | Bulk inserts | 50ms | 15ms | 3x |

API Documentation

Driver Configuration

interface DriverConfig {
  storageDir: string; // Directory for database files
  verbose?: boolean; // Log SQL statements
  readonly?: boolean; // Open in read-only mode
}

Creating the Driver

const driver = new BunSQLiteDriver({
  storageDir: './data',
  verbose: false, // Enable SQL logging
  readonly: false, // Read-write mode
});

Queries

// Find one
const user = User.findOne({ where: { username: 'alice' } });

// Find all with filters
const adults = User.findAll({
  where: { age: { $gte: 18 } },
  orderBy: [['age', 'DESC']],
  limit: 10,
});

// Count
const count = User.count({ status: 'active' });

// Aggregations
const totalAge = User.sum('age');
const avgAge = User.avg('age');
const maxAge = User.max('age');

Transactions

const result = orm.getDriver().transaction(() => {
  const user = User.create({ username: 'alice' });
  Profile.create({ user_id: user.id, bio: 'Hello' });
  return user;
});

Indexes

User.createIndex('idx_email', {
  unique: true,
  columns: ['email'],
});

User.createIndex('idx_user_status', {
  columns: ['status', 'created_at'],
});

Advanced Features

Multi-Database Support

const driver = new BunSQLiteDriver({
  storageDir: './data',
});

const orm = new ORM({ driver });

// Each database name creates a separate .sqlite file
const User = orm.define('users_db', 'users', userSchema);
const Product = orm.define('products_db', 'products', productSchema);

console.log(orm.getDatabases()); // ['users_db', 'products_db']

WAL Mode

Write-Ahead Logging is automatically enabled for better concurrency and performance.

Query Operators

// Comparison operators
User.findAll({ where: { age: { $gt: 18 } } }); // greater than
User.findAll({ where: { age: { $gte: 18 } } }); // greater than or equal
User.findAll({ where: { age: { $lt: 65 } } }); // less than
User.findAll({ where: { age: { $lte: 65 } } }); // less than or equal
User.findAll({ where: { age: { $ne: 25 } } }); // not equal

// Range operators
User.findAll({ where: { age: { $between: [18, 65] } } });
User.findAll({ where: { status: { $in: ['active', 'premium'] } } });
User.findAll({ where: { status: { $notIn: ['banned'] } } });

// Pattern matching
User.findAll({ where: { username: { $like: '%alice%' } } });

Comparison with @rinari/sqlite

| Feature | @rinari/sqlite | @rinari/bun-sqlite | | ------------ | --------------------------- | ------------------ | | Runtime | Node.js, Bun (experimental) | Bun only | | Backend | better-sqlite3 | bun:sqlite | | Performance | Fast | 3-6x faster | | Dependencies | better-sqlite3 | None (native) | | API | Identical | Identical |

Examples

See the examples/bun-sqlite-basic directory for a complete working example.

License

OpenUwU Open License (OUOL-1.0)