# 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/97/ac/532fd421631a587c337baaa3e020c21794f8d5a834e774607af43537c9de/locobuzz_python_orm-1.1.5.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.5",
"project_urls": {
"Homepage": "https://github.com/LocoBuzz-Solutions-Pvt-Ltd/locobuzz_database_orm"
},
"split_keywords": [
"locobuzz",
" python",
" database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "be57c48b84c2acf8dcdb32ec2fe84195b85e7615e11537000bc9c7cc05772fd7",
"md5": "f5ff378f9429fa40e78149028895b63f",
"sha256": "8cc83cff3e03de9b76bb9356918d77a75108c24b5c8f7fd3e6d5c6c555f19605"
},
"downloads": -1,
"filename": "locobuzz_python_orm-1.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f5ff378f9429fa40e78149028895b63f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<=3.12,>=3.8",
"size": 21630,
"upload_time": "2024-12-18T12:00:25",
"upload_time_iso_8601": "2024-12-18T12:00:25.089946Z",
"url": "https://files.pythonhosted.org/packages/be/57/c48b84c2acf8dcdb32ec2fe84195b85e7615e11537000bc9c7cc05772fd7/locobuzz_python_orm-1.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "97ac532fd421631a587c337baaa3e020c21794f8d5a834e774607af43537c9de",
"md5": "e4199afac7ce3c6f48b9ce9b3725eb1b",
"sha256": "9d6a1e52e0a26f6de0d9bb6e050d2d59be67d0ec76af57f5aaa8c73af74ce861"
},
"downloads": -1,
"filename": "locobuzz_python_orm-1.1.5.tar.gz",
"has_sig": false,
"md5_digest": "e4199afac7ce3c6f48b9ce9b3725eb1b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<=3.12,>=3.8",
"size": 18606,
"upload_time": "2024-12-18T12:00:26",
"upload_time_iso_8601": "2024-12-18T12:00:26.490180Z",
"url": "https://files.pythonhosted.org/packages/97/ac/532fd421631a587c337baaa3e020c21794f8d5a834e774607af43537c9de/locobuzz_python_orm-1.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-18 12:00:26",
"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"
}