Skip to main content

Reverse-Engineering SQLite Databases into Drizzle/Prisma Schemas, SVG ERDs, and DuckDB Analytics

How to profile tables with DuckDB SUMMARIZE, diff two .sqlite snapshots, and export CWE-1236 safe Excel files locally in your browser.

Updated 4 min readMarkdown
Part of seriesKivaroTools: Browser Engineering & Client-Side Architecture

Inheriting an undocumented .sqlite or .db file is a familiar headache. Maybe it came from a prototype, a mobile app backup, or a legacy microservice. Nobody left a schema diagram, half the foreign keys were never declared as constraints, and now you need to understand the data model, pull a clean Excel sheet for a stakeholder, and wire the tables into TypeScript.

Normally that means juggling four different tools: DB Browser for SQLite to peek at tables, a separate ERD tool to map relationships, a Python script to convert tables into .xlsx, and hand-writing Drizzle or Prisma models from sqlite_master output.

To collapse that workflow into one local browser tab, I built the SQLite & DuckDB Viewer, Editor, ERD & Forensic Studio on KivaroTools. Everything executes locally in browser memory via a zero-CDN TypeScript B-tree parser—no file uploads, no signup, and no desktop installs. Here is how four practical SQLite workflows work under the hood.

1. Profiling Unknown Tables in One Line with DuckDB SUMMARIZE

When you open an unfamiliar database with 15+ tables, writing manual SELECT COUNT(*), MIN(...), MAX(...), COUNT(DISTINCT ...) queries for every column is tedious.

DuckDB's analytical extensions solve this cleanly. Running SUMMARIZE on a SQLite table gives you column types, min/max bounds, null counts, and approximate cardinality in a single command—and EXCLUDE lets you drop noisy JSON blobs without listing 25 column names by hand:


-- Profile every column in the orders table in one shot

SUMMARIZE orders;



-- Inspect paid orders while dropping bulky JSON payloads

SELECT * EXCLUDE (metadata_json)

FROM orders

WHERE status = 'PAID'

ORDER BY amount_usd DESC;

In Tab 1 of the studio, you can run both standard SQLite queries (JOIN, PRAGMA, EXPLAIN QUERY PLAN) and DuckDB analytical queries (SUMMARIZE, DESCRIBE, SELECT * EXCLUDE, GROUP BY ALL) directly against loaded .sqlite, .db, .sqlite3, or .duckdb files—plus edit cells inline and save back a valid binary .sqlite file.

Half of the SQLite databases in the wild never declared explicit FOREIGN KEY constraints—they just have columns like organization_id or user_id sitting in child tables. A naive ERD generator that only reads PRAGMA foreign_key_list draws a pile of disconnected boxes.

Mapping both declared foreign keys and implicit *_id naming conventions gives you an accurate visual ER diagram (exportable as Vector .svg, Mermaid, or DBML) and lets you compile straight into TypeScript ORM definitions like Drizzle (schema.ts), Prisma (schema.prisma), or PostgreSQL migrations:


import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core';



export const users = sqliteTable('users', {

  id: integer('id').primaryKey({ autoIncrement: true }),

  organization_id: integer('organization_id')

    .notNull()

    .references(() => organizations.id),

  full_name: text('full_name').notNull(),

  plan_tier: text('plan_tier').notNull(),

});

Before migrating that schema to production, running a 12-point integrity audit (PRAGMA foreign_key_check + unindexed FK detection) catches orphaned child rows and missing foreign-key indexes that silently slow down JOINs.

3. Diffing Two SQLite Snapshots Locally (sqldiff)

When debugging why staging behaves differently from a local seed database, eyeballing two CREATE TABLE dumps wastes time.

Running a local side-by-side database diff compares two .sqlite or .sql files directly in browser memory—highlighting added, removed, and modified tables and generating a copy-ready ALTER TABLE SQL migration patch without sending either snapshot to an external server.

4. Exporting CWE-1236 Safe Excel (.xlsx) Spreadsheets

A subtle security bug when exporting user-generated database rows directly to .xlsx or .csv for non-technical teammates is spreadsheet formula injection (CWE-1236). If a text field starts with =, +, -, or @, Excel can evaluate it as a formula when someone opens the file.

When exporting tables to Excel (.xlsx) or RFC 4180 CSV from Tab 5, neutralizing leading formula triggers protects whoever opens the spreadsheet—alongside 9 other local export targets (binary .sqlite, Drizzle, Prisma, PostgreSQL, DuckDB, SQLite Dump, Mermaid, DBML, and a SHA-256 audit certificate).

Practical Limits & Architecture

  • Client-side scope: Database files are parsed and modified strictly inside browser RAM and are never uploaded to KivaroTools servers. Performance stays smooth up to roughly 100–250 MB.
  • When to use desktop tools: For multi-GB databases, heavy batch ETL, or SQLCipher / WhatsApp .crypt encrypted files, stick with desktop DB Browser for SQLite. For columnar .parquet, .avro, or .feather files, use the dedicated Parquet, Avro & Feather Viewer.
  • Stack: Built with Next.js (App Router), React, TypeScript, Tailwind CSS, and Cloudflare Workers, using a self-contained TypeScript B-tree parser so corporate CSP rules never block external .wasm CDN loads.

You can test the full workflow right away using the built-in SaaS Prod (cloudscale_saas_prod.sqlite), Forensic DB, or Chrome / iOS sample databases inside the KivaroTools SQLite & DuckDB Studio.

About the author

  • Founder & Lead Software Architect @ KivaroTools | BS Computer Science | Full-Stack & Systems Engineer (TypeScript, Next.js, Python, Java, C++, WebAssembly) | Privacy-First Web & Financial Engines

No comments yet. Be the first to comment.

KivaroTools: Browser Engineering & Client-Side Architecture

Part 16 of 17

A technical series exploring the engineering behind KivaroTools, including browser-based file processing, JavaScript and TypeScript architecture, memory management, application security, data parsing, performance optimization, and financial computation. Each article shares practical implementation insights, engineering decisions, testing approaches, and lessons learned while building reliable web utilities.

Up next6 Regular Expression Bugs That Pass Local Tests and Break in Production (Java, Python, Go & JS)From unanchored validation and broken Unicode word boundaries to Go RE2 panics and ReDoS—with exact fixes.

More from this blog