Registry / search / openchemlib-sqlite

openchemlib-sqlite

JSON →
library2.0.0jsnpmunverified

SQLite-backed molecular database for substructure, exact, and similarity search using OpenChemLib (OCL). Current version: 2.0.0, released September 2025. Uses Node.js built-in node:sqlite (requires Node >=22.5). Does not own the molecules table — you provide it. Key differentiator: works alongside your existing table, uses OCL 512-bit fingerprints, supports stereo-insensitive exact search via optional id_code_no_stereo column. Released as needed; mature library with active maintenance.

npm install openchemlib-sqlite
INSTALL
IMPORT
SIG · OPENCHEMLIB-SQLITE
O
openchemlib-sqlite
searchjavascriptv2.0.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.

MoleculesDBSQLite
import { MoleculesDBSQLite } from 'openchemlib-sqlite'
const { MoleculesDBSQLite } = require('openchemlib-sqlite')
Package is ESM-only. CommonJS require will fail with ERR_REQUIRE_ESM.
SearchMode
import { SearchMode } from 'openchemlib-sqlite'
SearchMode is an enum-like object with keys EXACT, SUBSTRUCTURE, SIMILARITY. Available since v2.0.0.
SearchResponse
import type { SearchResponse } from 'openchemlib-sqlite'
import { SearchResponse } from 'openchemlib-sqlite'
SearchResponse is a TypeScript type/interface, not a runtime value. Use import type to avoid bundling issues.

Set up an in-memory SQLite database, create molecules table, insert a molecule (caffeine), then substructure-search for benzene ring.

import { DatabaseSync } from 'node:sqlite'; import * as OCL from 'openchemlib'; import { MoleculesDBSQLite, SearchMode } from 'openchemlib-sqlite'; const db = new DatabaseSync(':memory:'); db.exec(` CREATE TABLE molecules ( id INTEGER PRIMARY KEY, id_code TEXT NOT NULL UNIQUE, id_code_no_stereo TEXT NOT NULL ) `); const molDB = new MoleculesDBSQLite(db, OCL, { entriesTable: 'molecules', idCodeNoStereoColumn: 'id_code_no_stereo', }); molDB.migrate(); const mol = OCL.Molecule.fromText('Cn1c(=O)c2c(ncn2C)n(C)c1=O'); if (!mol) throw new Error('Parse failed'); const idCode = mol.getIDCode(); const molNoStereo = mol.getCompactCopy(); molNoStereo.stripStereoInformation(); const idCodeNoStereo = molNoStereo.getIDCode(); const { lastInsertRowid } = db .prepare('INSERT INTO molecules (id_code, id_code_no_stereo) VALUES (?, ?)') .run(idCode, idCodeNoStereo); molDB.insert(Number(lastInsertRowid), mol); const query = OCL.Molecule.fromText('C1=CC=CC=C1'); const results = molDB.search(query, SearchMode.SUBSTRUCTURE); console.log(results.total);
Debug
Known issues
breakingNode.js version requirement: >=22.5.0. Using built-in node:sqlite module.
fix
Upgrade Node.js to v22.5.0 or later, or use older openchemlib-sqlite v1.x which did not require node:sqlite.
affects: >=2.0.0
breakingPackage is ESM-only since v2.0.0. No CommonJS support.
fix
Use import instead of require(). Ensure your project is configured for ESM (type: module in package.json).
affects: >=2.0.0
breakingPeer dependency openchemlib must be >=9.20.1.
fix
Install openchemlib@^9.20.1 alongside this package.
affects: >=2.0.0
gotchamigrate() must be called after constructor and before any insert/search. It creates the ocl_ss_index table.
fix
Ensure molDB.migrate() is called. It is idempotent.
affects: >=1.0.0
gotchaThe molecules table must be created by you before instantiating MoleculesDBSQLite. The library does not create it.
fix
Create your molecules table with appropriate columns before constructing MoleculesDBSQLite.
affects: >=1.0.0
gotchainsert() expects the entry ID as a number, not a BigInt. Using lastInsertRowid may return a BigInt in newer sqlite3 versions.
fix
Always convert lastInsertRowid to Number: molDB.insert(Number(lastInsertRowid), mol);
affects: >=2.0.0
gotchaSearch results do not include any data from your molecules table, only entryId and idCode. You must join yourself.
fix
After search, use the entryId to fetch additional columns from your table.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() on an ESM-only package (v2.x).
fix
Replace require() with import, and set type: module in package.json, or rename file to .mjs.
TypeError: db.prepare is not a function
Using a DatabaseSync instance (from node:sqlite) incorrectly. The library expects node:sqlite's DatabaseSync, not better-sqlite3 or other libraries.
fix
Use import { DatabaseSync } from 'node:sqlite' and create db = new DatabaseSync('path').
Error: entriesTable is required
Missing entriesTable in config options when constructing MoleculesDBSQLite.
fix
Provide entriesTable: 'your_table_name' in the config object.
Error: No such table: ocl_ss_index
migrate() was not called before attempting search or insert.
fix
Call molDB.migrate() after constructing MoleculesDBSQLite and before any operations.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
openchemlibrequiredPeer dependency: provides OCL molecule parsing, idCode generation, and fingerprint computation
Agent activity
28 hits · last 30 days
node
26
Resources