Registry / database / sqlite-docstore

sqlite-docstore

JSON →
library1.1.0jsnpmunverified

A lightweight MongoDB-like JSON document storage system backed by SQLite. Version 1.1.0 requires Node.js >=22. Provides familiar CRUD operations (insertOne, find, updateOne, deleteOne) on collections stored as SQLite tables. Supports rich queries with $in, $regex, aggregation ($match/$group), count, distinct. Differentiators: zero external dependencies beyond SQLite, in-memory or persistent options, direct raw SQL access. Ideal for small projects, edge deployments, or when avoiding a full MongoDB server.

npm install sqlite-docstore
INSTALL
IMPORT
SIG · SQLITE-DOCSTORE
S
sqlite-docstore
databasejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sqliteDocstore
import { sqliteDocstore } from 'sqlite-docstore'
const { sqliteDocstore } = require('sqlite-docstore')
ESM-only since v1.0; no default export exists
SqliteDocstoreFunctions
import type { SqliteDocstoreFunctions } from 'sqlite-docstore'
Available as a type import for TypeScript users

Initializes an in-memory database, creates a collection, inserts a document, queries it, and cleans up.

import { sqliteDocstore } from 'sqlite-docstore'; const db = sqliteDocstore.init(); // In-memory database; pass a filename for persistence const collection = 'users'; db.createCollection(collection); const { insertedId } = db.insertOne(collection, { name: 'Alice', age: 30 }); console.log('Inserted:', insertedId); const found = db.find(collection, { name: 'Alice' }); console.log('Found:', found); console.log('Count:', db.countDocuments(collection)); db.dropCollection(collection);
Debug
Known issues
gotcha.init() returns an object with methods, not a class instance; methods must be called on that object.
fix
Store the returned object: const db = sqliteDocstore.init();
affects: >=1.0
gotchaCollection must exist before inserting a document; SQLite Docstore does not auto-create collections.
fix
Call db.createCollection(name) before any insert/find operation.
affects: >=1.0
gotchaInsert operations return { insertedId: string } or { insertedCount: number }, not the MongoDB driver's full result object.
fix
Use .insertedId for the single insert ID, .insertedCount for multiple inserts.
affects: >=1.0
breakingThe library is ESM-only and requires Node >=22; no CommonJS support.
fix
Use ESM imports and upgrade Node.js to v22+.
affects: >=1.0
gotcha.init(fileName) returns a new instance each call; opening the same file twice creates two separate DB connections.
fix
Reuse the returned object or implement a singleton pattern.
affects: >=1.0
Errors
Common errors & fixes
TypeError: sqlite_docstore_1.default is not a function
Using default import instead of named import
fix
import { sqliteDocstore } from 'sqlite-docstore'
Error: Collection 'users' does not exist
Creating a collection is mandatory before any operation
fix
Call db.createCollection('users') before using the collection
ReferenceError: require is not defined in ES module scope
Using CommonJS require() in an ESM-only package
fix
Switch to ESM imports or use dynamic import()
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
sqlite-docstore — npm install sqlite-docstore · libregistry