{"id":17957,"library":"sqleton","title":"SQLite Schema Visualizer","description":"Sqleton is a command-line utility and Node.js library designed to visualize SQLite database schemas. It takes a SQLite database file or object and generates a graphical diagram, typically in formats like SVG, PNG, or PDF, by utilizing the external Graphviz engine for rendering. The current stable version is 4.0.0. While no explicit release cadence is documented, the project appears to be actively maintained. Key differentiators include its singular focus on SQLite, offering both a straightforward CLI for quick visualizations and a programmatic API for integration into Node.js applications. It provides options for customizing the graph layout, adding edge labels for foreign keys, specifying titles, fonts, and graph direction. Although it strictly supports SQLite, users can potentially visualize other database schemas by converting them to a SQLite format first.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/inukshuk/sqleton","tags":["javascript","sql","sqlite","visualize","visualizer","graphviz","diagram","dot"],"install":[{"cmd":"npm install sqleton","lang":"bash","label":"npm"},{"cmd":"yarn add sqleton","lang":"bash","label":"yarn"},{"cmd":"pnpm add sqleton","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary programmatic API is a default function export via CommonJS. While Node.js 18+ generally supports ESM, `sqleton`'s main module is intended for `require()` based consumption.","wrong":"import sqleton from 'sqleton'","symbol":"sqleton","correct":"const sqleton = require('sqleton')"}],"quickstart":{"code":"import Database from 'better-sqlite3';\nimport fs from 'node:fs';\n// Sqleton is a CommonJS module, so 'require' is the canonical way to import.\nconst sqleton = require('sqleton');\n\n// Create a dummy in-memory SQLite database for demonstration\nconst db = new Database(':memory:');\ndb.exec(`\n  CREATE TABLE users (\n    id INTEGER PRIMARY KEY,\n    name TEXT NOT NULL,\n    email TEXT UNIQUE\n  );\n\n  CREATE TABLE posts (\n    post_id INTEGER PRIMARY KEY,\n    user_id INTEGER NOT NULL,\n    title TEXT NOT NULL,\n    content TEXT,\n    FOREIGN KEY (user_id) REFERENCES users(id)\n  );\n\n  CREATE TABLE comments (\n    comment_id INTEGER PRIMARY KEY,\n    post_id INTEGER NOT NULL,\n    user_id INTEGER NOT NULL,\n    text TEXT NOT NULL,\n    FOREIGN KEY (post_id) REFERENCES posts(post_id),\n    FOREIGN KEY (user_id) REFERENCES users(id)\n  );\n`);\n\nconst outputPath = 'db_schema.svg';\nconst outputStream = fs.createWriteStream(outputPath);\n\n// Generate the schema diagram\nsqleton(db, outputStream, {\n  layout: 'dot', // Specify the Graphviz layout engine\n  title: 'My Application Schema',\n  direction: 'LR', // Graph direction: Left-to-Right\n  edgeLabels: true, // Show labels on foreign key edges\n})\n  .then(() => {\n    console.log(`Schema diagram generated successfully at ${outputPath}`);\n    outputStream.end();\n    db.close();\n  })\n  .catch((err: Error) => {\n    console.error('Failed to generate schema diagram:', err.message);\n    // Provide specific guidance for the common Graphviz error\n    if (err.message.includes('dot: not found') || err.message.includes('ENOENT')) {\n      console.error('Error: Graphviz `dot` command not found. Please ensure Graphviz is installed and in your system PATH.');\n      console.error('Installation instructions: http://www.graphviz.org/download/');\n    }\n    outputStream.end();\n    db.close();\n  });\n","lang":"typescript","description":"Demonstrates programmatic use of `sqleton` to generate an SVG diagram of a simple SQLite schema. It sets up an in-memory database with tables and foreign keys using `better-sqlite3`, then pipes the output to a file, also handling potential Graphviz execution errors."},"warnings":[{"fix":"Install Graphviz on your operating system. Common installation commands include: `brew install graphviz` (macOS), `sudo apt-get install graphviz` (Debian/Ubuntu), `pacman -Sy graphviz` (Arch Linux). Refer to http://www.graphviz.org/download/ for platform-specific instructions.","message":"Sqleton relies on the external Graphviz application (`dot` command) for rendering diagrams. Graphviz must be installed separately on your operating system and accessible via the system's PATH. Without Graphviz, sqleton will fail to generate any graphical output, often with an 'ENOENT' error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you are using a SQLite database. For other database systems, consider using dedicated visualization tools for that specific database or evaluating if a schema conversion to SQLite is feasible for visualization purposes.","message":"Sqleton is exclusively designed to visualize SQLite database schemas. While creative workarounds (e.g., dumping and converting schemas) might exist for other database types, direct native support for PostgreSQL, MySQL, or other non-SQLite databases is not provided.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Install Graphviz on your system. For example: `brew install graphviz` (macOS) or `sudo apt-get install graphviz` (Debian/Ubuntu).","cause":"The Graphviz 'dot' executable is not found in the system's PATH, preventing sqleton from rendering the diagram.","error":"Error: spawnSync dot ENOENT"},{"fix":"Use the CommonJS `require` syntax: `const sqleton = require('sqleton');`","cause":"Attempting to use ES module `import sqleton from 'sqleton'` when the package is primarily CommonJS and exports its main function via `module.exports = function (...)`.","error":"TypeError: sqleton is not a function"},{"fix":"Verify the path to your SQLite database file and ensure it exists and is readable by the process running `sqleton`.","cause":"The specified SQLite database file does not exist at the given path, or the Node.js process lacks sufficient read permissions for the file or its directory.","error":"Error: SQLITE_CANTOPEN: unable to open database file"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}