Skip to content

shahradelahi/isomorphic-sqlite

Repository files navigation

isomorphic-sqlite

CI NPM Version MIT License npm bundle size Install Size

isomorphic-sqlite is an isomorphic SQLite driver for Node.js and Bun. It automatically uses the best available driver, prioritizing built-in options like node:sqlite and bun:sqlite, and falling back to better-sqlite3 when necessary.


📦 Installation

npm install isomorphic-sqlite
Install using your favorite package manager

pnpm

pnpm install isomorphic-sqlite

yarn

yarn add isomorphic-sqlite

If you are using a Node.js version older than v22.5.0, you will also need to install better-sqlite3:

npm install better-sqlite3

📖 Usage

import { Database } from 'isomorphic-sqlite';

// Open an in-memory database
const db = new Database(':memory:');

// Create a table
await db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');

// Insert some data
await db.exec('INSERT INTO users (name) VALUES (?), (?)', ['Alice', 'Bob']);

// Query for a single row
const alice = await db.get<{ id: number; name: string }>(
  'SELECT * FROM users WHERE name = ?',
  ['Alice']
);
console.log(alice); // { id: 1, name: 'Alice' }

// Query for all rows
const users = await db.all<{ id: number; name: string }>(
  'SELECT * FROM users'
);
console.log(users); // [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ]

// Close the database
await db.close();

📚 Documentation

For all configuration options, please see the API docs.

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! 🙏

📑 References

License

MIT © Shahrad Elahi and contributors.

Releases

No releases published

Packages

No packages published