{"library":"sqleton","title":"SQLite Schema Visualizer","type":"library","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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install sqleton"],"cli":{"name":"sqleton","version":null}},"imports":["const sqleton = require('sqleton')"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/inukshuk/sqleton","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sqleton","openapi_spec":null,"status_page":null,"smithery":null},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}