Database Utils for Node.js (Abandoned)

raw JSON →
1.4.1 verified Thu Apr 23 auth: no javascript abandoned

This `database-utils` package is an **abandoned and unmaintained** Node.js utility library, last updated over a decade ago with version `1.4.1`. It aimed to provide fundamental tools for interacting with databases, including a `SqlBuilder` for constructing SQL queries programmatically and an `ORM` (Object Relational Mapper) for higher-level database interactions. However, its development ceased long ago, and the project's GitHub repository explicitly carries a deprecation notice, advising against its use for anything other than historical research. It does not follow modern best practices, lacks essential features (as indicated by its extensive `TODO` list), and likely has significant compatibility issues with contemporary Node.js versions and database systems. Users seeking database utilities, SQL builders, or ORMs should explore actively maintained alternatives in the Node.js ecosystem, such as `knex`, `sequelize`, `typeorm`, or `prisma`.

error TypeError: SqlDriver is not a constructor
cause Attempting to import `SqlDriver` using ES module syntax (`import { SqlDriver } from 'database-utils';`) when the package only supports CommonJS `require`.
fix
Use CommonJS require syntax: const { SqlDriver } = require('database-utils');
error UnhandledPromiseRejectionWarning: DeprecationWarning: This project is not maintained.
cause Node.js runtime or another dependency is detecting usage of an old or deprecated module, specifically this `database-utils` package, and issuing a warning.
fix
This warning is inherent to using an abandoned package. The only true fix is to replace database-utils with an actively maintained library. You might be able to suppress DeprecationWarning in Node.js, but this is highly discouraged as it hides critical information.
error Error: Column 'some_field' cannot be used with LIKE operator in query builder.
cause Attempting to use advanced SQL operators like `like`, `notlike`, `between`, or `having` which are listed in the `TODO` section of the `README` but were likely never implemented.
fix
The feature is missing. You cannot use it with this library. You would need to manually write the raw SQL query or, preferably, migrate to a more robust SQL builder or ORM that supports these operators.
breaking This project is explicitly marked as 'DEPRECATED' and 'not maintained' by its author on GitHub. It does not receive updates, bug fixes, or security patches, making it unsuitable for production use.
fix Migrate to an actively maintained SQL builder or ORM library (e.g., Knex.js, Sequelize, TypeORM, Prisma) to ensure security, stability, and compatibility with modern Node.js and database systems.
gotcha The `README` lists a substantial 'TODO' section, indicating many planned features (e.g., `notlike`, `replace`, `having`, `between`, `limit in update()`, `ORM`) were never implemented or completed. Relying on advertised features might lead to missing functionality or unexpected behavior.
fix Thoroughly review the source code for implemented features or assume that any feature not explicitly demonstrated in the limited examples is likely unfinished or buggy. Prefer alternative, well-documented libraries.
gotcha The library's age (last updated over 10 years ago) means it likely has significant compatibility issues with modern Node.js runtimes (e.g., ES modules, async/await patterns, newer buffer APIs) and contemporary database drivers/standards.
fix Avoid using this library in new projects. If encountering it in legacy code, extreme caution and extensive testing are required for any upgrades or changes to the Node.js environment or database systems. Migration is strongly recommended.
gotcha The primary `SqlDriver` example for generating SQL is based on concatenation, which historically can be prone to SQL injection vulnerabilities if not handled meticulously. While `getQuerySql()` attempts to provide parameterized queries, the overall architecture might not enforce modern best practices for preventing such attacks.
fix Always use a database driver's native parameterized query features with prepared statements. If forced to use this library, meticulously sanitize all user inputs and never directly concatenate untrusted data into SQL strings. However, the safest fix is to switch to a modern, actively maintained library designed with security in mind.
npm install database-utils
yarn add database-utils
pnpm add database-utils

Demonstrates basic SQL query construction using the `SqlDriver` class and how to retrieve both raw SQL and parameterized queries. It highlights the library's role as a SQL builder rather than a full database connector. The commented-out ORM section illustrates potential (but speculative) usage.

const { SqlDriver } = require('database-utils');

const sqlDriver = new SqlDriver();

// Example 1: Basic SELECT query
let sql = sqlDriver
  .parameters()
  .select('*')
  .from('user')
  .where('id', 5)
  .get();

console.log('Generated SQL (Example 1):', sql); // Expected: select * from user where id = 5

// Example 2: SELECT query with parameterized values (demonstrating getQuerySql for prepared statements)
let parameterizedSql = sqlDriver
  .parameters()
  .select('*')
  .from('products')
  .where('category', 'Electronics')
  .where('price', '>', 100)
  .getQuerySql();

let query = parameterizedSql[0];
let params = parameterizedSql[1];

console.log('\nGenerated SQL (Example 2 - Query):', query);   // Expected: select * from products where category = ? and price > ?
console.log('Generated SQL (Example 2 - Parameters):', params); // Expected: ['Electronics', 100]

// Note: This library only builds SQL strings; it does not connect to or execute queries against a database.
// You would typically pass these generated SQL strings and parameters to an actual database driver (e.g., 'mysql2' or 'pg').

// Example: Illustrating an intended (but potentially unimplemented/buggy) ORM-like interaction
/*
const { ORM } = require('database-utils');
const MyModel = new ORM('my_table');

async function runOrmExample() {
  try {
    // Assuming a 'find' method would exist, but this is highly speculative
    const data = await MyModel.find({ id: 1 });
    console.log('\nORM-like find result:', data);

    // Or perhaps a 'create' method
    const newRecord = await MyModel.create({ name: 'Test', value: 123 });
    console.log('ORM-like create result:', newRecord);

  } catch (error) {
    console.error('\nError during ORM-like operation:', error.message);
  }
}
runOrmExample();
*/