npxbase
v1.0.0
Published
A professional and modular database management library for Node.js with support for MySQL, PostgreSQL, and MongoDB.
Maintainers
Readme
NPXBase
NPXBase is a professional, flexible, and modular database management library for Node.js. It provides a unified interface for interacting with multiple database types, such as MySQL, PostgreSQL, and MongoDB. The library is designed to make database operations easier, more efficient, and secure.
🚀 Features
- Unified Interface: Seamlessly interact with various databases through a common API.
- Adapters for Multiple Databases: Supports MySQL, PostgreSQL, and MongoDB out of the box.
- Connection Management: Provides efficient connection pooling and management.
- Query Execution: Simplified methods for executing database queries.
- Error Handling: Comprehensive error messages and logging.
- Modular Design: Easily extendable to support additional databases.
📦 Installation
To install NPXBase, use npm or yarn:
npm install npxbaseor
yarn add npxbase🛠️ Usage
Example: Connecting to MySQL
const { DBManager, MySQLAdapter } = require("npxbase");
(async () => {
const mysqlAdapter = new MySQLAdapter();
const db = new DBManager(mysqlAdapter);
await db.connect({
host: "localhost",
user: "root",
password: "password",
database: "test_db",
});
const results = await db.query("SELECT * FROM users");
console.log("Results:", results);
await db.disconnect();
})();Example: Connecting to PostgreSQL
const { DBManager, PostgresAdapter } = require("npxbase");
(async () => {
const postgresAdapter = new PostgresAdapter();
const db = new DBManager(postgresAdapter);
await db.connect({
host: "localhost",
user: "postgres",
password: "password",
database: "test_db",
});
const results = await db.query("SELECT * FROM users");
console.log("Results:", results);
await db.disconnect();
})();📖 API Reference
DBManager
The DBManager class is the core of NPXBase. It manages connections and executes queries.
Methods:
connect(config): Establishes a connection to the database.disconnect(): Closes the connection to the database.query(sql, params): Executes a SQL query with optional parameters.
Adapters
MySQLAdapter: Adapter for MySQL.PostgresAdapter: Adapter for PostgreSQL.MongoDBAdapter(planned): Adapter for MongoDB (coming soon).
⚙️ Configuration
Each adapter requires a configuration object to establish a connection. Examples:
MySQL Configuration
{
host: "localhost",
user: "root",
password: "password",
database: "test_db",
}PostgreSQL Configuration
{
host: "localhost",
user: "postgres",
password: "password",
database: "test_db",
}🧪 Testing
To run tests, install development dependencies and run the test script:
npm test🌟 Contributions
Contributions are welcome! If you want to add new features, fix bugs, or improve the documentation, feel free to submit a pull request.
📜 License
NPXBase is licensed under the MIT License.
