{"id":16327,"library":"database-js-common","title":"Database-JS Common Utilities","description":"The `database-js-common` package provides essential utility functions designed to support the implementation of drivers within the broader `database-js` ecosystem. Its primary function is the robust parsing of database connection strings, converting complex URL-like formats (e.g., `key=value&nested[key]=value`) into structured JavaScript objects. It includes optional automatic type conversion for common values like booleans and numbers. Currently at version 1.0.1, this package serves as a foundational internal component for `database-js` drivers. However, it's crucial to note that the main `database-js` project itself, which this package supports, was last published in June 2021 (version 3.0.11). This indicates that the entire `database-js` ecosystem, including this common utility module, is likely in an abandoned or unmaintained state, with no active development, regular release cadence, or ongoing support. Its key differentiator is its specialized connection string parsing logic tailored for the `database-js` framework, rather than being a general-purpose, actively maintained parsing library.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/mlaanderson/database-js-common","tags":["javascript","database-js"],"install":[{"cmd":"npm install database-js-common","lang":"bash","label":"npm"},{"cmd":"yarn add database-js-common","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-js-common","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS (CJS) only. Direct ESM `import` statements are not supported, requiring CJS `require()`.","wrong":"import Common from 'database-js-common';","symbol":"Common","correct":"const Common = require('database-js-common');"},{"note":"The `parseConnectionParameters` function is a property of the default CommonJS export, not a named export.","wrong":"import { parseConnectionParameters } from 'database-js-common';","symbol":"parseConnectionParameters","correct":"const Common = require('database-js-common');\nconst params = Common.parseConnectionParameters(paramString);"}],"quickstart":{"code":"const Common = require('database-js-common');\n\n// Example connection string mimicking URL parameters\nconst connectionString1 = \"host=localhost&port=3306&user=root&password=secret&database=mydb\";\nconst parsedParams1 = Common.parseConnectionParameters(connectionString1);\nconsole.log('Parsed simple parameters:', parsedParams1);\n/* Expected output:\n{\n  host: 'localhost',\n  port: '3306',\n  user: 'root',\n  password: 'secret',\n  database: 'mydb'\n}*/\n\n// Example with nested parameters and type conversion\nconst connectionString2 = \"key1=value1&key2[subkey1]=true&key2[subkey2]=123.45&key3[]=itemA&key3[]=itemB\";\nconst parsedParams2 = Common.parseConnectionParameters(connectionString2, true);\nconsole.log('Parsed nested with type conversion:', parsedParams2);\n/* Expected output:\n{\n  key1: 'value1',\n  key2: { subkey1: true, subkey2: 123.45 },\n  key3: [ 'itemA', 'itemB' ]\n}*/\n\n// Demonstrate how to use the parsed parameters in a driver-like context\nfunction createMockConnection(options) {\n    console.log('Creating connection with options:', options);\n    return { status: 'connected', config: options };\n}\n\nconst driverConnectionConfig = {\n    Hostname: 'my-db-server',\n    Port: '5432',\n    Username: 'dbuser',\n    Password: process.env.DB_PASSWORD ?? 'default_password',\n    Database: 'app_data',\n    Parameters: \"timeout=3000&ssl=true&poolSize=10\"\n};\n\nconst driverParams = Common.parseConnectionParameters(driverConnectionConfig.Parameters, true);\nconst finalConnection = createMockConnection({\n    host: driverConnectionConfig.Hostname || 'localhost',\n    port: parseInt(driverConnectionConfig.Port) || 5432,\n    user: driverConnectionConfig.Username || 'root',\n    password: driverConnectionConfig.Password,\n    database: driverConnectionConfig.Database,\n    parameters: driverParams\n});\nconsole.log('Final connection object:', finalConnection);","lang":"javascript","description":"This quickstart demonstrates how to use `parseConnectionParameters` to convert various connection string formats into structured JavaScript objects, including handling nested keys and optional type conversion. It also shows a basic integration into a mock database driver setup."},"warnings":[{"fix":"Consider migrating to a more actively maintained database abstraction layer or ORM for current and future projects. If retaining, be aware of potential vulnerabilities and compatibility issues, especially with newer Node.js releases.","message":"The `database-js` ecosystem, including `database-js-common`, appears to be unmaintained. The main `database-js` package has not been updated in approximately five years (last published June 2021). This implies a lack of security updates, bug fixes, or compatibility improvements for modern Node.js versions or JavaScript features.","severity":"breaking","affected_versions":">=1.0.1"},{"fix":"Always use `const Common = require('database-js-common');` to import this package in both CJS and ESM environments (as ESM can import CJS default exports, albeit with some limitations).","message":"This package is implemented as a CommonJS (CJS) module. Attempting to use `import` statements (ECMAScript Modules, ESM) directly will result in errors in a pure ESM environment.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure your environment correctly treats the file as CommonJS, or use dynamic `import()` if you must import a CJS module from an ESM file: `const Common = await import('database-js-common'); Common.default.parseConnectionParameters(...)`.","cause":"Attempting to use `require()` in an ES Module (ESM) context without proper setup, or when the file is treated as an ESM module (e.g., `.mjs` extension or `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined"},{"fix":"Ensure you are calling it as `Common.parseConnectionParameters(...)` after assigning the `require` result to a variable like `Common`.","cause":"Incorrectly accessing the `parseConnectionParameters` function. It is a method of the object returned by `require('database-js-common')`.","error":"TypeError: Common.parseConnectionParameters is not a function"}],"ecosystem":"npm"}