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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kysely-node-sqlite

v1.1.0

Published

Kysely SQLite adapter for the built in node:sqlite module

Downloads

28

Readme

kysely-node-sqlite

A powerful SQLite dialect for Kysely, leveraging the native Node.js SQLite module (node:sqlite). This dialect provides robust statement caching, comprehensive error handling, and configurable pragma settings for optimal SQLite performance.

NPM Version License

Features

  • 🚀 Built for the native Node.js SQLite module (node:sqlite)
  • 💾 Intelligent statement caching with LRU implementation
  • ⚡ Configurable SQLite pragma settings for different environments
  • 🛡️ Comprehensive error handling with detailed SQLite error codes
  • 🔄 Transaction support with configurable isolation levels
  • 📊 Database introspection capabilities
  • 🔍 Advanced query compilation
  • 💪 TypeScript support

Installation

npm install kysely-node-sqlite

Usage

Basic Setup

import { Kysely } from 'kysely'
import { SqliteDialect } from 'kysely-node-sqlite'
import { DatabaseSync } from 'node:sqlite'

interface Database {
  users: {
    id: number
    name: string
    created_at: Date
  }
}

const db = new Kysely<Database>({
  dialect: new SqliteDialect({
    database: new DatabaseSync('path/to/database.db')
  })
})

With Statement Caching

const db = new Kysely<Database>({
  dialect: new SqliteDialect({
    database: new DatabaseSync('path/to/database.db'),
    stmntCache: {
      maxSize: 1000,
      maxAge: 1000 * 60 * 60 // 1 hour
    }
  })
})

Environment-specific Pragma Configuration

import { PragmaDefaults } from 'kysely-node-sqlite'

const db = new Kysely<Database>({
  dialect: new SqliteDialect({
    database: new DatabaseSync('path/to/database.db'),
    mode: 'production', // Uses production pragma defaults
    // Or customize specific pragmas
    pragmaConfig: {
      journalMode: 'WAL',
      synchronous: 'NORMAL',
      foreignKeys: true,
      // ... other pragma settings
    }
  })
})

Error Handling

import { isNodeSqliteError, SqliteConstraints } from 'kysely-node-sqlite'

try {
  await db.insertInto('users')
    .values({
      id: 1,
      name: 'John',
      created_at: new Date()
    })
    .execute()
} catch (error) {
  if (SqliteConstraints.isUniqueConstraint(error)) {
    console.log('Duplicate entry detected')
  } else if (SqliteConstraints.isForeignKeyConstraint(error)) {
    console.log('Foreign key violation')
  } else if (isNodeSqliteError(error)) {
    console.log(`SQLite error: ${error.errorType}`)
  }
}

Transaction Support

await db.transaction().execute(async (trx) => {
  await trx.insertInto('users')
    .values({
      id: 1,
      name: 'John',
      created_at: new Date()
    })
    .execute()
})

Configuration Options

SqliteDialectConfig

interface SqliteDialectConfig {
  // Required: SQLite database instance or factory function
  database: SqliteDatabase | (() => Promise<SqliteDatabase>)

  // Optional: Called after connection is established
  onCreateConnection?: (connection: DatabaseConnection) => Promise<void>

  // Optional: Environment mode for pragma defaults
  mode?: 'development' | 'testing' | 'production'

  // Optional: Custom pragma configuration
  pragmaConfig?: PragmaConfig

  // Optional: Transaction isolation mode
  transactionMode?: 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE'

  // Optional: Statement cache configuration
  stmntCache?: StatementCacheOption
}

PragmaConfig

interface PragmaConfig {
  journalMode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF'
  synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA'
  cacheSize?: number
  mmapSize?: number
  tempStore?: 'DEFAULT' | 'FILE' | 'MEMORY'
  lockingMode?: 'NORMAL' | 'EXCLUSIVE'
  busyTimeout?: number
  foreignKeys?: boolean
  walAutocheckpoint?: number
  trustedSchema?: boolean
}

Error Types

The library provides comprehensive error handling through the NodeSqliteError class and utility functions:

import {
  isNodeSqliteError,
  SqliteConstraints,
  type NodeSqliteErrorData
} from 'kysely-node-sqlite'

// Check for specific constraint violations
SqliteConstraints.isUniqueConstraint(error)
SqliteConstraints.isForeignKeyConstraint(error)
SqliteConstraints.isNotNullConstraint(error)
SqliteConstraints.isCheckConstraint(error)

// Access detailed error information
if (isNodeSqliteError(error)) {
  console.log(error.errorType)    // Type of error
  console.log(error.code)         // Error code
  console.log(error.errcode)      // SQLite error code
  console.log(error.errstr)       // SQLite error string
}

License

BSD-style license found in the LICENSE file.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

  • Kysely - The SQL query builder this dialect is built for
  • Node.js SQLite - The native SQLite implementation