The `database-query` package (current stable version 1.1.22) provides a unified, lightweight interface for connecting to and executing queries against a variety of popular SQL and NoSQL databases. It supports MySQL, PostgreSQL, MS SQL Server, Oracle, MongoDB, and ClickHouse. This library acts as an abstraction layer, aiming to simplify interaction with diverse database systems through a consistent API, rather than requiring developers to learn the specific nuances of each underlying database driver. Its core functionality focuses on direct query execution and connection management, distinguishing it from full-fledged ORMs or complex query builders. The project, maintained by the Apipost-Team, has a moderate release cadence, with the last significant update in October 2023, indicating an active or maintenance status. Its primary differentiator lies in offering broad multi-database support under a single, streamlined API, facilitating integration in applications that require connectivity to multiple data stores.
npm install database-queryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `database-query` for a MySQL connection, execute a parameterized SELECT query, and perform an INSERT operation, including proper connection management with environment variables.
Refer to the official `oracledb` documentation for detailed installation prerequisites and troubleshooting. Ensure your build environment has the necessary tools and libraries configured before installing `database-query`.
Always consult the official documentation for the specific database driver (e.g., `pg`, `mssql`, `mysql`) to understand database-specific configuration options. Test connections thoroughly with minimal configurations first.
Always use parameterized queries (`db.query('SELECT * FROM users WHERE id = ?', [userId])`) to prevent SQL injection. Avoid directly embedding user-provided input into SQL strings.If you encounter installation issues or wish to minimize dependencies, consider managing specific database drivers yourself and manually passing their connection details or client instances if the library's API allows, or investigate alternatives that allow explicit installation of only desired drivers. Otherwise, accept the bundled dependencies.
Manually try `npm install <missing-driver-package>` (e.g., `npm install mysql`) to ensure the required database driver is present in your `node_modules`.
Verify the `host` and `port` in your database configuration. Ensure the database server is running and accessible from the machine running your application. Check firewall rules on both client and server.
Double-check your `user` and `password` credentials. Ensure the database user has permissions to connect from the `host` where your application is running, and to the `database` you specified.