{"id":25806,"library":"jsite-database","title":"jsite-database","description":"Database module for the JSite package, providing a structured database interface with built-in auditing (SCD Type 4 row-based and column-based change tracking), SQL formatting via sql-formatter, SQL generation via json-sql-builder2, and MySQL support via the mysql module. Version 6.1.0 is the latest stable release. Key differentiators include integrated audit trail capabilities and customizable configuration for format, SQL dialect, and MySQL connection.","status":"active","version":"6.1.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install jsite-database","lang":"bash","label":"npm"},{"cmd":"yarn add jsite-database","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsite-database","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for MySQL database connections","package":"mysql","optional":true},{"reason":"Used for formatting SQL queries","package":"sql-formatter","optional":true},{"reason":"Used for building SQL queries from JSON","package":"json-sql-builder2","optional":true}],"imports":[{"note":"This package uses CommonJS and does not provide ESM exports.","wrong":"import JSiteDatabase from 'jsite-database'","symbol":"JSiteDatabase","correct":"const JSiteDatabase = require('jsite-database')"},{"note":"Named export, not default export.","wrong":"const JSiteDatabase = require('jsite-database').default","symbol":"JSiteDatabase","correct":"const { JSiteDatabase } = require('jsite-database')"},{"note":"JSiteDatabase is a constructor, must be instantiated with new.","wrong":"const db = JSiteDatabase(options)","symbol":"JSiteDatabase","correct":"const Database = new JSiteDatabase(options)"}],"quickstart":{"code":"const path = require('path');\nconst JSiteDatabase = require('jsite-database');\n\nconst db = new JSiteDatabase({\n  format: { indent: '  ' },\n  mysql: {\n    host: process.env.MYSQL_HOST ?? 'localhost',\n    user: process.env.MYSQL_USER ?? 'root',\n    password: process.env.MYSQL_PASSWORD ?? '',\n    database: process.env.MYSQL_DATABASE ?? 'test'\n  },\n  sql: {\n    language: 'mysql',\n    options: { quoteIdentifiers: true }\n  },\n  audit: 'row',\n  files: {\n    db: path.join(__dirname, 'private', 'mysql')\n  }\n});\n\ndb.ready()\n  .then(() => console.log('Database ready'))\n  .catch(err => console.error(err));","lang":"javascript","description":"Initializes a JSiteDatabase instance with MySQL connection and row-based auditing, then waits for readiness via ready()."},"warnings":[{"fix":"Review auditing documentation and migrate your schema accordingly.","message":"In version 6.x, the audit option 'row' and 'column' changed behavior. Ensure you review the new SCD implementation.","severity":"breaking","affected_versions":"6.0.0 - 6.1.0"},{"fix":"Use 'json-sql-builder2' as a dependency.","message":"The package uses 'json-sql-builder2' which has a different API than 'json-sql-builder'. Ensure you have the correct version.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Replace 'mysql' with 'mysql2' in options or use a compatible wrapper.","message":"The 'mysql' package used for MySQL connections is deprecated since version 6.0.0. Consider migrating to 'mysql2'.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Always use 'new JSiteDatabase(options)'.","message":"JSiteDatabase must be instantiated with 'new'. Calling it as a regular function will throw an error.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install jsite-database' in your project directory.","cause":"Package not installed in node_modules","error":"Error: Cannot find module 'jsite-database'"},{"fix":"Use 'const JSiteDatabase = require('jsite-database')' and instantiate with 'new JSiteDatabase()'.","cause":"Using default import or calling function without 'new'","error":"TypeError: JSiteDatabase is not a constructor"},{"fix":"Ensure MySQL is running on localhost:3306, or provide correct host and port in options.","cause":"MySQL server not running or incorrect host/port","error":"Error: connect ECONNREFUSED 127.0.0.1:3306"},{"fix":"Use one of 'row', 'column', or omit for default 'row'.","cause":"Passing invalid audit option","error":"Error: Unknown audit method: 'all'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}