locobuzz-python-orm


Namelocobuzz-python-orm JSON
Version 1.1.2 PyPI version JSON
download
home_pagehttps://github.com/LocoBuzz-Solutions-Pvt-Ltd/locobuzz_database_orm
SummaryPython database orm functions for Locobuzz, common code that is required in all projects
upload_time2024-09-25 08:55:03
maintainerNone
docs_urlNone
authorAtharva Udavant
requires_python<=3.12,>=3.8
licenseNone
keywords locobuzz python database
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Locobuzz Python ORM
```markdown
# Database Connection Manager

A Python package for managing database connections in both synchronous and asynchronous contexts using SQLAlchemy. The package provides two main classes: `SyncDatabase` for synchronous operations and `AsyncDatabase` for asynchronous operations with PostgreSQL.

## Features

- Singleton pattern to ensure a single instance of the database connection.
- Support for multiple databases with connection pooling.
- Asynchronous support for improved performance in `AsyncDatabase`.
- Easy switching between different databases.
- Metadata initialization for table management.

## Installation

To install the package, you can use pip:

```bash
pip install locobuzz_python_orm  # Replace with the actual package name
```

## Usage

### Synchronous Database Management

To use the `SyncDatabase`, follow these steps:

```python
from database_helper.database.sync_db import SyncDatabase

# Initialize the SyncDatabase
sync_db = SyncDatabase(connection_string='postgresql://user:password@localhost/dbname')

# Use the SyncDatabase context manager
with sync_db:
    # Execute a query
    results = sync_db.execute_query("SELECT * FROM your_table;")
    print(results)
```

### Asynchronous Database Management

For the `AsyncDatabase`, you'll use `async` and `await` keywords:

```python
import asyncio
from database_helper.database.async_db import AsyncDatabase

async def main():
    # Initialize the AsyncDatabase
    async_db = AsyncDatabase(connection_string='postgresql://user:password@localhost/dbname')

    async with async_db:
        # Execute a query asynchronously
        results = await async_db.execute_query("SELECT * FROM your_table;")
        print(results)

# Run the async main function
asyncio.run(main())
```

### Switching Databases

Both classes support switching databases on the fly:

```python
# For SyncDatabase
sync_db.switch_database('new_dbname')

# For AsyncDatabase
await async_db.switch_database('new_dbname')
```

### Initializing Tables

You can initialize tables metadata using:

```python
# For SyncDatabase
sync_db.initialize_tables(['your_table1', 'your_table2'])

# For AsyncDatabase
await async_db.initialize_tables(['your_table1', 'your_table2'])
```

## Error Handling

Both classes include basic error handling. If an error occurs during database operations, exceptions will be raised. You can implement additional logging as needed.

## Dependencies

- SQLAlchemy
- Database connectors such as `pyodbc`, `pymysql`, `psycopg2`, `aioodbc`, `aiomysql`, `asyncpg` 

## Author

Atharva Udavant

[GitHub Profile](https://github.com/Atharva17062002)  
[Email](mailto:17.atharva@gmail.com)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LocoBuzz-Solutions-Pvt-Ltd/locobuzz_database_orm",
    "name": "locobuzz-python-orm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<=3.12,>=3.8",
    "maintainer_email": null,
    "keywords": "locobuzz, python, database",
    "author": "Atharva Udavant",
    "author_email": "atharva.udavant@locobuzz.com",
    "download_url": "https://files.pythonhosted.org/packages/29/da/482ca5ff56685243e3e894bc49ea84b1e3d0104494c7cb7b0d204707b7d8/locobuzz_python_orm-1.1.2.tar.gz",
    "platform": null,
    "description": "# Locobuzz Python ORM\r\n```markdown\r\n# Database Connection Manager\r\n\r\nA Python package for managing database connections in both synchronous and asynchronous contexts using SQLAlchemy. The package provides two main classes: `SyncDatabase` for synchronous operations and `AsyncDatabase` for asynchronous operations with PostgreSQL.\r\n\r\n## Features\r\n\r\n- Singleton pattern to ensure a single instance of the database connection.\r\n- Support for multiple databases with connection pooling.\r\n- Asynchronous support for improved performance in `AsyncDatabase`.\r\n- Easy switching between different databases.\r\n- Metadata initialization for table management.\r\n\r\n## Installation\r\n\r\nTo install the package, you can use pip:\r\n\r\n```bash\r\npip install locobuzz_python_orm  # Replace with the actual package name\r\n```\r\n\r\n## Usage\r\n\r\n### Synchronous Database Management\r\n\r\nTo use the `SyncDatabase`, follow these steps:\r\n\r\n```python\r\nfrom database_helper.database.sync_db import SyncDatabase\r\n\r\n# Initialize the SyncDatabase\r\nsync_db = SyncDatabase(connection_string='postgresql://user:password@localhost/dbname')\r\n\r\n# Use the SyncDatabase context manager\r\nwith sync_db:\r\n    # Execute a query\r\n    results = sync_db.execute_query(\"SELECT * FROM your_table;\")\r\n    print(results)\r\n```\r\n\r\n### Asynchronous Database Management\r\n\r\nFor the `AsyncDatabase`, you'll use `async` and `await` keywords:\r\n\r\n```python\r\nimport asyncio\r\nfrom database_helper.database.async_db import AsyncDatabase\r\n\r\nasync def main():\r\n    # Initialize the AsyncDatabase\r\n    async_db = AsyncDatabase(connection_string='postgresql://user:password@localhost/dbname')\r\n\r\n    async with async_db:\r\n        # Execute a query asynchronously\r\n        results = await async_db.execute_query(\"SELECT * FROM your_table;\")\r\n        print(results)\r\n\r\n# Run the async main function\r\nasyncio.run(main())\r\n```\r\n\r\n### Switching Databases\r\n\r\nBoth classes support switching databases on the fly:\r\n\r\n```python\r\n# For SyncDatabase\r\nsync_db.switch_database('new_dbname')\r\n\r\n# For AsyncDatabase\r\nawait async_db.switch_database('new_dbname')\r\n```\r\n\r\n### Initializing Tables\r\n\r\nYou can initialize tables metadata using:\r\n\r\n```python\r\n# For SyncDatabase\r\nsync_db.initialize_tables(['your_table1', 'your_table2'])\r\n\r\n# For AsyncDatabase\r\nawait async_db.initialize_tables(['your_table1', 'your_table2'])\r\n```\r\n\r\n## Error Handling\r\n\r\nBoth classes include basic error handling. If an error occurs during database operations, exceptions will be raised. You can implement additional logging as needed.\r\n\r\n## Dependencies\r\n\r\n- SQLAlchemy\r\n- Database connectors such as `pyodbc`, `pymysql`, `psycopg2`, `aioodbc`, `aiomysql`, `asyncpg` \r\n\r\n## Author\r\n\r\nAtharva Udavant\r\n\r\n[GitHub Profile](https://github.com/Atharva17062002)  \r\n[Email](mailto:17.atharva@gmail.com)\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python database orm functions for Locobuzz,  common code that is required in all projects",
    "version": "1.1.2",
    "project_urls": {
        "Homepage": "https://github.com/LocoBuzz-Solutions-Pvt-Ltd/locobuzz_database_orm"
    },
    "split_keywords": [
        "locobuzz",
        " python",
        " database"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2cc65122bd7c75150d1f21ab863bb8581e570e6c69ed740c071a2b3680dd1181",
                "md5": "f25fe97ef7195c04bbf1f1ea1dba0642",
                "sha256": "b128b59f78a2b23886b670da2d40f4a3d4e2fe1563872d63f8a09e41a9747b73"
            },
            "downloads": -1,
            "filename": "locobuzz_python_orm-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f25fe97ef7195c04bbf1f1ea1dba0642",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<=3.12,>=3.8",
            "size": 9947,
            "upload_time": "2024-09-25T08:55:01",
            "upload_time_iso_8601": "2024-09-25T08:55:01.291954Z",
            "url": "https://files.pythonhosted.org/packages/2c/c6/5122bd7c75150d1f21ab863bb8581e570e6c69ed740c071a2b3680dd1181/locobuzz_python_orm-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "29da482ca5ff56685243e3e894bc49ea84b1e3d0104494c7cb7b0d204707b7d8",
                "md5": "29a7fe49d73c1e0918c1fcedfcc9ac10",
                "sha256": "ab93a35c431e0f3f8d2e932b977b904f9537d15dc5de937fbc9dc7e080308705"
            },
            "downloads": -1,
            "filename": "locobuzz_python_orm-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "29a7fe49d73c1e0918c1fcedfcc9ac10",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<=3.12,>=3.8",
            "size": 8284,
            "upload_time": "2024-09-25T08:55:03",
            "upload_time_iso_8601": "2024-09-25T08:55:03.054855Z",
            "url": "https://files.pythonhosted.org/packages/29/da/482ca5ff56685243e3e894bc49ea84b1e3d0104494c7cb7b0d204707b7d8/locobuzz_python_orm-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-25 08:55:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "LocoBuzz-Solutions-Pvt-Ltd",
    "github_project": "locobuzz_database_orm",
    "github_not_found": true,
    "lcname": "locobuzz-python-orm"
}
        
Elapsed time: 0.39150s