db-engine-factory


Namedb-engine-factory JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/skyblue-will/db_engine_factory
SummaryDB Engine Factory: Simplify connecting to MySQL, MSSQL, and PostgreSQL databases through a single, unified configuration.
upload_time2024-10-27 19:23:48
maintainerNone
docs_urlNone
authorYour Name
requires_python>=3.6
licenseMIT
keywords database sqlalchemy mysql postgresql mssql database engine factory
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DB Engine Factory

**Version**: 0.1.4  
**Author**: Will Palmer  
**Description**: `DB Engine Factory` is a Python library designed to simplify connecting to multiple database types (MySQL, MSSQL, PostgreSQL) using SQLAlchemy. Connections are configured via a central `.ini` file, streamlining database management for applications needing to work with diverse database systems.

---

## Table of Contents

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
  - [Creating Database Engines](#creating-database-engines)
  - [Testing Connections](#testing-connections)
- [AI Assistance Prompt](#ai-assistance-prompt)
- [Running Tests](#running-tests)
- [Contributing](#contributing)

---

## Installation

1. **Install the package from PyPI**:
   ```bash
   pip install db-engine-factory
   ```

2. **Create a configuration file**: Ensure your `.ini` configuration file (e.g., `db_config.ini`) is in the project root or the directory where you run scripts.

## Configuration

### Setting Up Your `.ini` Configuration File

Create a `.ini` file (e.g., `db_config.ini`) in the project’s root directory. Each section represents a database configuration.

#### Example `db_config.ini`

```ini
# MySQL Database
[mysql_db]
type = mysql
user = myuser
password = mypassword
host = localhost
port = 3306
database = mydatabase

# MSSQL Database
[mssql_db]
type = mssql
server = sqlserver.example.com
database = mydatabase
username = myuser
password = mypassword

# PostgreSQL Database
[postgres_db]
type = postgres
user = myuser
password = mypassword
host = localhost
port = 5432
database = mydatabase
```

**Explanation of Fields**

- **type**: Database type (`mysql`, `mssql`, or `postgres`).
- **user/username**: Database username.
- **password**: Database password.
- **host/server**: Database server address.
- **port**: Database port (`3306` for MySQL, `5432` for PostgreSQL).
- **database**: Name of the database.

## Usage

### Creating Database Engines

Use the functions in `db_connection.py` to create database engines. Each function accepts a `db_identifier` matching a section in `db_config.ini`.

```python
from db_engine_factory.db_connection import create_mysql_engine, create_mssql_engine, create_postgres_engine

# Create a MySQL engine
mysql_engine = create_mysql_engine("mysql_db")

# Create an MSSQL engine
mssql_engine = create_mssql_engine("mssql_db")

# Create a PostgreSQL engine
postgres_engine = create_postgres_engine("postgres_db")
```

### Function Parameters

- **create_mysql_engine(db_identifier)**: Creates a MySQL engine based on the `.ini` configuration.
- **create_mssql_engine(db_identifier)**: Creates an MSSQL engine using the specified `.ini` section.
- **create_postgres_engine(db_identifier)**: Creates a PostgreSQL engine per `.ini` configuration.

### Testing Connections

Run `test_db_engine_factory` from the command line to test connections to all configured databases with a simple `SELECT 1` query.

```bash
test_db_engine_factory
```

This outputs success or error messages for each database connection attempt, confirming if `.ini` configurations are correct.

## AI Assistance Prompt

If you need help from an AI assistant, use this example prompt:

> "I'm using `DB Engine Factory` to connect to MySQL, MSSQL, and PostgreSQL databases, configured in a `.ini` file under sections like `[mysql_db]`, `[mssql_db]`, and `[postgres_db]`. I use functions like `create_mysql_engine(db_identifier)`, `create_mssql_engine(db_identifier)`, and `create_postgres_engine(db_identifier)`. Could you help troubleshoot any connection issues or verify query results?"

## Running Tests

The package includes a test script for verifying database connections defined in the `.ini` file.

1. Confirm `.ini` file is correctly configured.
2. Run the test command:
   ```bash
   test_db_engine_factory
   ```

This script connects to each database and runs a `SELECT 1` query, displaying connection results in the console.

## Contributing

To contribute:

1. **Fork** the repository.
2. **Create a branch** (`git checkout -b feature/YourFeature`).
3. **Commit your changes** (`git commit -m 'Add a new feature'`).
4. **Push to the branch** (`git push origin feature/YourFeature`).
5. **Open a pull request**.

If you encounter issues or have suggestions, please [open an issue on GitHub](https://github.com/skyblue-will/db_engine_factory/issues).

--- 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/skyblue-will/db_engine_factory",
    "name": "db-engine-factory",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "database, SQLAlchemy, MySQL, PostgreSQL, MSSQL, database engine factory",
    "author": "Your Name",
    "author_email": "Will Palmer <will@willpalmer.co.uk>",
    "download_url": "https://files.pythonhosted.org/packages/77/2f/758c9f185ce59294d8d0f33f0afa8eb896e80f5e831e379b0454fda37ca8/db_engine_factory-0.1.4.tar.gz",
    "platform": null,
    "description": "# DB Engine Factory\n\n**Version**: 0.1.4  \n**Author**: Will Palmer  \n**Description**: `DB Engine Factory` is a Python library designed to simplify connecting to multiple database types (MySQL, MSSQL, PostgreSQL) using SQLAlchemy. Connections are configured via a central `.ini` file, streamlining database management for applications needing to work with diverse database systems.\n\n---\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage](#usage)\n  - [Creating Database Engines](#creating-database-engines)\n  - [Testing Connections](#testing-connections)\n- [AI Assistance Prompt](#ai-assistance-prompt)\n- [Running Tests](#running-tests)\n- [Contributing](#contributing)\n\n---\n\n## Installation\n\n1. **Install the package from PyPI**:\n   ```bash\n   pip install db-engine-factory\n   ```\n\n2. **Create a configuration file**: Ensure your `.ini` configuration file (e.g., `db_config.ini`) is in the project root or the directory where you run scripts.\n\n## Configuration\n\n### Setting Up Your `.ini` Configuration File\n\nCreate a `.ini` file (e.g., `db_config.ini`) in the project\u2019s root directory. Each section represents a database configuration.\n\n#### Example `db_config.ini`\n\n```ini\n# MySQL Database\n[mysql_db]\ntype = mysql\nuser = myuser\npassword = mypassword\nhost = localhost\nport = 3306\ndatabase = mydatabase\n\n# MSSQL Database\n[mssql_db]\ntype = mssql\nserver = sqlserver.example.com\ndatabase = mydatabase\nusername = myuser\npassword = mypassword\n\n# PostgreSQL Database\n[postgres_db]\ntype = postgres\nuser = myuser\npassword = mypassword\nhost = localhost\nport = 5432\ndatabase = mydatabase\n```\n\n**Explanation of Fields**\n\n- **type**: Database type (`mysql`, `mssql`, or `postgres`).\n- **user/username**: Database username.\n- **password**: Database password.\n- **host/server**: Database server address.\n- **port**: Database port (`3306` for MySQL, `5432` for PostgreSQL).\n- **database**: Name of the database.\n\n## Usage\n\n### Creating Database Engines\n\nUse the functions in `db_connection.py` to create database engines. Each function accepts a `db_identifier` matching a section in `db_config.ini`.\n\n```python\nfrom db_engine_factory.db_connection import create_mysql_engine, create_mssql_engine, create_postgres_engine\n\n# Create a MySQL engine\nmysql_engine = create_mysql_engine(\"mysql_db\")\n\n# Create an MSSQL engine\nmssql_engine = create_mssql_engine(\"mssql_db\")\n\n# Create a PostgreSQL engine\npostgres_engine = create_postgres_engine(\"postgres_db\")\n```\n\n### Function Parameters\n\n- **create_mysql_engine(db_identifier)**: Creates a MySQL engine based on the `.ini` configuration.\n- **create_mssql_engine(db_identifier)**: Creates an MSSQL engine using the specified `.ini` section.\n- **create_postgres_engine(db_identifier)**: Creates a PostgreSQL engine per `.ini` configuration.\n\n### Testing Connections\n\nRun `test_db_engine_factory` from the command line to test connections to all configured databases with a simple `SELECT 1` query.\n\n```bash\ntest_db_engine_factory\n```\n\nThis outputs success or error messages for each database connection attempt, confirming if `.ini` configurations are correct.\n\n## AI Assistance Prompt\n\nIf you need help from an AI assistant, use this example prompt:\n\n> \"I'm using `DB Engine Factory` to connect to MySQL, MSSQL, and PostgreSQL databases, configured in a `.ini` file under sections like `[mysql_db]`, `[mssql_db]`, and `[postgres_db]`. I use functions like `create_mysql_engine(db_identifier)`, `create_mssql_engine(db_identifier)`, and `create_postgres_engine(db_identifier)`. Could you help troubleshoot any connection issues or verify query results?\"\n\n## Running Tests\n\nThe package includes a test script for verifying database connections defined in the `.ini` file.\n\n1. Confirm `.ini` file is correctly configured.\n2. Run the test command:\n   ```bash\n   test_db_engine_factory\n   ```\n\nThis script connects to each database and runs a `SELECT 1` query, displaying connection results in the console.\n\n## Contributing\n\nTo contribute:\n\n1. **Fork** the repository.\n2. **Create a branch** (`git checkout -b feature/YourFeature`).\n3. **Commit your changes** (`git commit -m 'Add a new feature'`).\n4. **Push to the branch** (`git push origin feature/YourFeature`).\n5. **Open a pull request**.\n\nIf you encounter issues or have suggestions, please [open an issue on GitHub](https://github.com/skyblue-will/db_engine_factory/issues).\n\n--- \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "DB Engine Factory: Simplify connecting to MySQL, MSSQL, and PostgreSQL databases through a single, unified configuration.",
    "version": "0.1.4",
    "project_urls": {
        "Documentation": "https://github.com/skyblue-will/db_engine_factory#readme",
        "Homepage": "https://github.com/skyblue-will/db_engine_factory",
        "Source": "https://github.com/skyblue-will/db_engine_factory",
        "Tracker": "https://github.com/skyblue-will/db_engine_factory/issues"
    },
    "split_keywords": [
        "database",
        " sqlalchemy",
        " mysql",
        " postgresql",
        " mssql",
        " database engine factory"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "503dfd4a9e69d52deae51b056fa746dc04ece7856bf58c19e8b2be74217c368c",
                "md5": "c6bda9931ffeabb62cf5df60372ddcf0",
                "sha256": "3263eb9e87d5cf064ec81fd2e0127784e5d19d859fd314953d1dc2fb9578f537"
            },
            "downloads": -1,
            "filename": "db_engine_factory-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6bda9931ffeabb62cf5df60372ddcf0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5169,
            "upload_time": "2024-10-27T19:23:45",
            "upload_time_iso_8601": "2024-10-27T19:23:45.849087Z",
            "url": "https://files.pythonhosted.org/packages/50/3d/fd4a9e69d52deae51b056fa746dc04ece7856bf58c19e8b2be74217c368c/db_engine_factory-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "772f758c9f185ce59294d8d0f33f0afa8eb896e80f5e831e379b0454fda37ca8",
                "md5": "686975752890dfc261f13b3deaf4d17f",
                "sha256": "476abe9ebf5cb786ee66e5b255d8bc4ce443b604a95786c459a951e62412c754"
            },
            "downloads": -1,
            "filename": "db_engine_factory-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "686975752890dfc261f13b3deaf4d17f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5844,
            "upload_time": "2024-10-27T19:23:48",
            "upload_time_iso_8601": "2024-10-27T19:23:48.126022Z",
            "url": "https://files.pythonhosted.org/packages/77/2f/758c9f185ce59294d8d0f33f0afa8eb896e80f5e831e379b0454fda37ca8/db_engine_factory-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-27 19:23:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "skyblue-will",
    "github_project": "db_engine_factory",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "db-engine-factory"
}
        
Elapsed time: 0.36630s