Registry / database / database-js-common

database-js-common

JSON →
library1.0.1jsnpmunverified

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.

npm install database-js-common
INSTALL
IMPORT
SIG · DATABASE-JS-COMMON
D
database-js-common
databasejavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Common
const Common = require('database-js-common');
import Common from 'database-js-common';
This package is CommonJS (CJS) only. Direct ESM `import` statements are not supported, requiring CJS `require()`.
parseConnectionParameters
const Common = require('database-js-common'); const params = Common.parseConnectionParameters(paramString);
import { parseConnectionParameters } from 'database-js-common';
The `parseConnectionParameters` function is a property of the default CommonJS export, not a named export.

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.

const Common = require('database-js-common'); // Example connection string mimicking URL parameters const connectionString1 = "host=localhost&port=3306&user=root&password=secret&database=mydb"; const parsedParams1 = Common.parseConnectionParameters(connectionString1); console.log('Parsed simple parameters:', parsedParams1); /* Expected output: { host: 'localhost', port: '3306', user: 'root', password: 'secret', database: 'mydb' }*/ // Example with nested parameters and type conversion const connectionString2 = "key1=value1&key2[subkey1]=true&key2[subkey2]=123.45&key3[]=itemA&key3[]=itemB"; const parsedParams2 = Common.parseConnectionParameters(connectionString2, true); console.log('Parsed nested with type conversion:', parsedParams2); /* Expected output: { key1: 'value1', key2: { subkey1: true, subkey2: 123.45 }, key3: [ 'itemA', 'itemB' ] }*/ // Demonstrate how to use the parsed parameters in a driver-like context function createMockConnection(options) { console.log('Creating connection with options:', options); return { status: 'connected', config: options }; } const driverConnectionConfig = { Hostname: 'my-db-server', Port: '5432', Username: 'dbuser', Password: process.env.DB_PASSWORD ?? 'default_password', Database: 'app_data', Parameters: "timeout=3000&ssl=true&poolSize=10" }; const driverParams = Common.parseConnectionParameters(driverConnectionConfig.Parameters, true); const finalConnection = createMockConnection({ host: driverConnectionConfig.Hostname || 'localhost', port: parseInt(driverConnectionConfig.Port) || 5432, user: driverConnectionConfig.Username || 'root', password: driverConnectionConfig.Password, database: driverConnectionConfig.Database, parameters: driverParams }); console.log('Final connection object:', finalConnection);
Debug
Known issues
breakingThe `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.
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.
affects: >=1.0.1
gotchaThis 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.
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).
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
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`).
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(...)`.
TypeError: Common.parseConnectionParameters is not a function
Incorrectly accessing the `parseConnectionParameters` function. It is a method of the object returned by `require('database-js-common')`.
fix
Ensure you are calling it as `Common.parseConnectionParameters(...)` after assigning the `require` result to a variable like `Common`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
database-js-common — npm install database-js-common · libregistry