1.0.0 โ€ข Published 6 months ago

npxbase v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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 npxbase

or

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.

1.0.0

6 months ago