app
JLCPCB Parts Library
Public Made by Adomby adom
Check the JLCPCB / LCSC parts library before you fab — Basic vs Extended tier, LCSC stock and assembly pricing, so you avoid surprise feeder-setup fees. CLI, a Hydrogen app, and a shared backend.
// Quick FTS index rebuild — the rowid column in search_fts got out of
// sync with components.rowid (=lcsc). Drop + repopulate from scratch.
//
// DB path:
// 1. First positional argument
// 2. $JLCPCB_DB_PATH env var
// 3. ./jlcpcb-components.sqlite3 (cwd-relative fallback)
const Database = require("better-sqlite3");
const dbPath = process.argv[2]
|| process.env.JLCPCB_DB_PATH
|| "./jlcpcb-components.sqlite3";
console.log("opening", dbPath);
const db = new Database(dbPath);
db.pragma("journal_mode = WAL");
console.log("dropping old search_fts...");
db.exec("DROP TABLE IF EXISTS search_fts");
db.exec("CREATE VIRTUAL TABLE search_fts USING fts5(lcsc, mfr, package, description, content=\"\")");
const total = db.prepare("SELECT COUNT(*) as n FROM components").get().n;
const ins = db.prepare("INSERT INTO search_fts(rowid, lcsc, mfr, package, description) VALUES (?, ?, ?, ?, ?)");
console.log("indexing", total, "rows...");
const batch = 10000; let done = 0; let off = 0;
while (off < total) {
const rows = db.prepare("SELECT lcsc, mfr, package, description, extra FROM components ORDER BY lcsc LIMIT ? OFFSET ?").all(batch, off);
const tx = db.transaction(() => {
for (const r of rows) {
let d = r.description || "";
if (r.extra) { try {
const x = JSON.parse(r.extra);
if (x.description) d = x.description;
if (x.title && x.title !== d) d += " " + x.title;
if (x.attributes) d += " " + Object.values(x.attributes).filter(v => typeof v === "string").join(" ");
} catch {} }
// CRITICAL: use lcsc as the fts rowid so the join c.rowid = fts.rowid works
ins.run(r.lcsc, String(r.lcsc), r.mfr || "", r.package || "", d);
}
});
tx();
off += batch; done += rows.length;
if (done % 50000 === 0 || done === total) process.stdout.write("\r "+done+"/"+total);
}
console.log("\ndone");