{"id":45688,"library":"openchemlib-sqlite","title":"openchemlib-sqlite","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/cheminfo/openchemlib-sqlite","tags":["javascript","chemistry","sqlite","substructure","openchemlib","molecules"],"install":[{"cmd":"npm install openchemlib-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add openchemlib-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add openchemlib-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: provides OCL molecule parsing, idCode generation, and fingerprint computation","package":"openchemlib","optional":false}],"imports":[{"note":"Package is ESM-only. CommonJS require will fail with ERR_REQUIRE_ESM.","wrong":"const { MoleculesDBSQLite } = require('openchemlib-sqlite')","symbol":"MoleculesDBSQLite","correct":"import { MoleculesDBSQLite } from 'openchemlib-sqlite'"},{"note":"SearchMode is an enum-like object with keys EXACT, SUBSTRUCTURE, SIMILARITY. Available since v2.0.0.","wrong":"","symbol":"SearchMode","correct":"import { SearchMode } from 'openchemlib-sqlite'"},{"note":"SearchResponse is a TypeScript type/interface, not a runtime value. Use import type to avoid bundling issues.","wrong":"import { SearchResponse } from 'openchemlib-sqlite'","symbol":"SearchResponse","correct":"import type { SearchResponse } from 'openchemlib-sqlite'"}],"quickstart":{"code":"import { DatabaseSync } from 'node:sqlite';\nimport * as OCL from 'openchemlib';\nimport { MoleculesDBSQLite, SearchMode } from 'openchemlib-sqlite';\n\nconst db = new DatabaseSync(':memory:');\ndb.exec(`\n  CREATE TABLE molecules (\n    id INTEGER PRIMARY KEY,\n    id_code TEXT NOT NULL UNIQUE,\n    id_code_no_stereo TEXT NOT NULL\n  )\n`);\n\nconst molDB = new MoleculesDBSQLite(db, OCL, {\n  entriesTable: 'molecules',\n  idCodeNoStereoColumn: 'id_code_no_stereo',\n});\nmolDB.migrate();\n\nconst mol = OCL.Molecule.fromText('Cn1c(=O)c2c(ncn2C)n(C)c1=O');\nif (!mol) throw new Error('Parse failed');\nconst idCode = mol.getIDCode();\nconst molNoStereo = mol.getCompactCopy();\nmolNoStereo.stripStereoInformation();\nconst idCodeNoStereo = molNoStereo.getIDCode();\n\nconst { lastInsertRowid } = db\n  .prepare('INSERT INTO molecules (id_code, id_code_no_stereo) VALUES (?, ?)')\n  .run(idCode, idCodeNoStereo);\n\nmolDB.insert(Number(lastInsertRowid), mol);\n\nconst query = OCL.Molecule.fromText('C1=CC=CC=C1');\nconst results = molDB.search(query, SearchMode.SUBSTRUCTURE);\nconsole.log(results.total);","lang":"typescript","description":"Set up an in-memory SQLite database, create molecules table, insert a molecule (caffeine), then substructure-search for benzene ring."},"warnings":[{"fix":"Upgrade Node.js to v22.5.0 or later, or use older openchemlib-sqlite v1.x which did not require node:sqlite.","message":"Node.js version requirement: >=22.5.0. Using built-in node:sqlite module.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use import instead of require(). Ensure your project is configured for ESM (type: module in package.json).","message":"Package is ESM-only since v2.0.0. No CommonJS support.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Install openchemlib@^9.20.1 alongside this package.","message":"Peer dependency openchemlib must be >=9.20.1.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure molDB.migrate() is called. It is idempotent.","message":"migrate() must be called after constructor and before any insert/search. It creates the ocl_ss_index table.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Create your molecules table with appropriate columns before constructing MoleculesDBSQLite.","message":"The molecules table must be created by you before instantiating MoleculesDBSQLite. The library does not create it.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always convert lastInsertRowid to Number: molDB.insert(Number(lastInsertRowid), mol);","message":"insert() expects the entry ID as a number, not a BigInt. Using lastInsertRowid may return a BigInt in newer sqlite3 versions.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"After search, use the entryId to fetch additional columns from your table.","message":"Search results do not include any data from your molecules table, only entryId and idCode. You must join yourself.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.0':20 '2025':23 '22.5':33 '512':52 'activ':74 'alongsid':46 'back':6 'bit':53 'built':27 'built-in':26 'chemistri':77 'code':64 'column':67 'current':18 'databas':8 'differenti':44 'exact':11,59 'exist':48 'fingerprint':54 'id':63 'insensit':58 'javascript':76 'key':43 'librari':72 'mainten':75 'matur':71 'molecul':38,81 'molecular':7 'need':70 'node':29,32 'node.js':25 'ocl':17,51 'openchemlib':2,16,80 'openchemlib-sqlit':1 'option':62 'provid':41 'releas':21,68 'requir':31 'search':14,60 'septemb':22 'similar':13 'sqlite':3,5,30,78 'sqlite-back':4 'stereo':57,66 'stereo-insensit':56 'substructur':10,79 'support':55 'tabl':39,49 'use':15,24,50 'version':19 'via':61 'work':45","created_at":"2026-06-07T12:56:14.265474+00:00","updated_at":"2026-06-07T12:56:14.265474+00:00","problems":[{"fix":"Replace require() with import, and set type: module in package.json, or rename file to .mjs.","cause":"Using CommonJS require() on an ESM-only package (v2.x).","error":"ERR_REQUIRE_ESM: require() of ES Module"},{"fix":"Use import { DatabaseSync } from 'node:sqlite' and create db = new DatabaseSync('path').","cause":"Using a DatabaseSync instance (from node:sqlite) incorrectly. The library expects node:sqlite's DatabaseSync, not better-sqlite3 or other libraries.","error":"TypeError: db.prepare is not a function"},{"fix":"Provide entriesTable: 'your_table_name' in the config object.","cause":"Missing entriesTable in config options when constructing MoleculesDBSQLite.","error":"Error: entriesTable is required"},{"fix":"Call molDB.migrate() after constructing MoleculesDBSQLite and before any operations.","cause":"migrate() was not called before attempting search or insert.","error":"Error: No such table: ocl_ss_index"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/cheminfo/openchemlib-sqlite#readme","github":"https://github.com/cheminfo/openchemlib-sqlite","docs":null,"changelog":null,"pypi":null,"npm":"openchemlib-sqlite","openapi_spec":null,"status_page":null,"smithery":null,"categories":["search"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}