# asyncpg_lite
```markdown
`asyncpg_lite` is a Python library designed to facilitate asynchronous interactions with a PostgreSQL database using
SQLAlchemy and asyncpg. This library provides methods for connecting to the database, creating tables, inserting,
updating, selecting, and deleting data. It also includes functionality for managing table schemas and handling conflict
resolutions during data insertion.
```
## Features
- **Asynchronous Database Operations**: Utilizes asyncio and SQLAlchemy for non-blocking database interactions.
- **Dynamic Table Management**: Create, update, delete, and drop tables dynamically.
- **Conflict Resolution**: Handle unique key conflicts during data insertion with update or ignore strategies.
- **Logging**: Integrated logging to monitor database operations and issues.
## Installation
Install the library using pip:
```bash
pip install --upgrade asyncpg_lite
```
## Usage example
```python
import asyncio
from asyncpg_lite import DatabaseManager
import logging
async def main_work():
from sqlalchemy import Integer, String
async with DatabaseManager(db_url= "postgresql://admin:sdaDSfa231@194.2.170.207:5432/my_db",
log_level=logging.DEBUG,
deletion_password="djdahEWE33a@@das") as db:
await db.create_table(table_name='my_table_name', columns=[
{"name": "user_id", "type": Integer, "options": {"primary_key": True, "autoincrement": False}},
{"name": "first_name", "type": String},
{"name": "last_name", "type": String},
{"name": "age", "type": Integer},
])
user_info = {'user_id': 1, 'first_name': 'Alexey', 'last_name': 'Yakovenko', 'age': 31}
await db.insert_data_with_update(table_name='my_table_name',
records_data=user_info,
conflict_column='user_id',
update_on_conflict=False)
users_info = [{'user_id': 1, 'first_name': 'Alex', 'last_name': 'Yakovenko', 'age': 31},
{'user_id': 2, 'first_name': 'Oleg', 'last_name': 'Antonov', 'age': 20},
{'user_id': 3, 'first_name': 'Dmitro', 'last_name': 'Pavlych', 'age': 14},
{'user_id': 4, 'first_name': 'Ivan', 'last_name': 'Sidorov', 'age': 66},
{'user_id': 5, 'first_name': 'John', 'last_name': 'Doe', 'age': 81}]
await db.insert_data_with_update(table_name='my_table_name',
records_data=users_info,
conflict_column='user_id',
update_on_conflict=True)
all_data = await db.select_data('my_table_name')
for i in all_data:
print(i)
one_data = await db.select_data('my_table_name', one_dict=True, where_dict={'user_id': 1})
print(one_data)
data_with_filters = await db.select_data('my_table_name',
where_dict=[{'user_id': 1}, {'user_id': 3}, {'last_name': 'Doe'}])
for i in data_with_filters:
print(i)
# delete example 1
await db.delete_data(table_name='my_table_name', where_dict={'user_id': 3})
# delete example 2
await db.delete_data(table_name='my_table_name', where_dict=[{'user_id': 2}, {'user_id': 5}])
all_data = await db.select_data('my_table_name')
for i in all_data:
print(i)
if __name__ == "__main__":
asyncio.run(main_work())
```
## License
Этот проект лицензируется по лицензии [MIT](https://choosealicense.com/licenses/mit/).
Raw data
{
"_id": null,
"home_page": "https://github.com/Yakvenalex/asyncpg_lite",
"name": "asyncpg-lite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Alexey Yakovenko",
"author_email": "mr.mnogo@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ba/e1/9bad6b01339b4021bbbe048ea51cf9abd41d363b7213c414dd2a9a2f74db/asyncpg_lite-0.3.1.3.tar.gz",
"platform": null,
"description": "# asyncpg_lite\r\n\r\n```markdown\r\n`asyncpg_lite` is a Python library designed to facilitate asynchronous interactions with a PostgreSQL database using\r\nSQLAlchemy and asyncpg. This library provides methods for connecting to the database, creating tables, inserting,\r\nupdating, selecting, and deleting data. It also includes functionality for managing table schemas and handling conflict\r\nresolutions during data insertion.\r\n\r\n```\r\n\r\n## Features\r\n\r\n- **Asynchronous Database Operations**: Utilizes asyncio and SQLAlchemy for non-blocking database interactions.\r\n- **Dynamic Table Management**: Create, update, delete, and drop tables dynamically.\r\n- **Conflict Resolution**: Handle unique key conflicts during data insertion with update or ignore strategies.\r\n- **Logging**: Integrated logging to monitor database operations and issues.\r\n\r\n## Installation\r\n\r\nInstall the library using pip:\r\n\r\n```bash\r\npip install --upgrade asyncpg_lite\r\n```\r\n\r\n## Usage example\r\n\r\n```python\r\nimport asyncio\r\nfrom asyncpg_lite import DatabaseManager\r\nimport logging\r\n\r\nasync def main_work():\r\n from sqlalchemy import Integer, String\r\n async with DatabaseManager(db_url= \"postgresql://admin:sdaDSfa231@194.2.170.207:5432/my_db\", \r\n log_level=logging.DEBUG, \r\n deletion_password=\"djdahEWE33a@@das\") as db:\r\n await db.create_table(table_name='my_table_name', columns=[\r\n {\"name\": \"user_id\", \"type\": Integer, \"options\": {\"primary_key\": True, \"autoincrement\": False}},\r\n {\"name\": \"first_name\", \"type\": String},\r\n {\"name\": \"last_name\", \"type\": String},\r\n {\"name\": \"age\", \"type\": Integer},\r\n ])\r\n user_info = {'user_id': 1, 'first_name': 'Alexey', 'last_name': 'Yakovenko', 'age': 31}\r\n await db.insert_data_with_update(table_name='my_table_name',\r\n records_data=user_info,\r\n conflict_column='user_id',\r\n update_on_conflict=False)\r\n\r\n users_info = [{'user_id': 1, 'first_name': 'Alex', 'last_name': 'Yakovenko', 'age': 31},\r\n {'user_id': 2, 'first_name': 'Oleg', 'last_name': 'Antonov', 'age': 20},\r\n {'user_id': 3, 'first_name': 'Dmitro', 'last_name': 'Pavlych', 'age': 14},\r\n {'user_id': 4, 'first_name': 'Ivan', 'last_name': 'Sidorov', 'age': 66},\r\n {'user_id': 5, 'first_name': 'John', 'last_name': 'Doe', 'age': 81}]\r\n\r\n await db.insert_data_with_update(table_name='my_table_name',\r\n records_data=users_info,\r\n conflict_column='user_id',\r\n update_on_conflict=True)\r\n\r\n all_data = await db.select_data('my_table_name')\r\n for i in all_data:\r\n print(i)\r\n\r\n one_data = await db.select_data('my_table_name', one_dict=True, where_dict={'user_id': 1})\r\n print(one_data)\r\n\r\n data_with_filters = await db.select_data('my_table_name',\r\n where_dict=[{'user_id': 1}, {'user_id': 3}, {'last_name': 'Doe'}])\r\n\r\n for i in data_with_filters:\r\n print(i)\r\n\r\n # delete example 1\r\n await db.delete_data(table_name='my_table_name', where_dict={'user_id': 3})\r\n\r\n # delete example 2\r\n await db.delete_data(table_name='my_table_name', where_dict=[{'user_id': 2}, {'user_id': 5}])\r\n\r\n all_data = await db.select_data('my_table_name')\r\n for i in all_data:\r\n print(i)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(main_work())\r\n```\r\n\r\n## License\r\n\r\n\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438 [MIT](https://choosealicense.com/licenses/mit/).\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple asynchronous library based on SQLAlchemy, powered by asyncpg",
"version": "0.3.1.3",
"project_urls": {
"Homepage": "https://github.com/Yakvenalex/asyncpg_lite"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78ccaec8c26ae20016627eccc0c017fab649a3b90e742069a2bd208aa525f8b4",
"md5": "3e0d64594235082f2c8326fb7df9f6d0",
"sha256": "c8cae7ddfceda900ef2c062570f059cddfaa5d173b36ee78c5891de5d6e98b77"
},
"downloads": -1,
"filename": "asyncpg_lite-0.3.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3e0d64594235082f2c8326fb7df9f6d0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 6590,
"upload_time": "2024-06-20T20:05:58",
"upload_time_iso_8601": "2024-06-20T20:05:58.244880Z",
"url": "https://files.pythonhosted.org/packages/78/cc/aec8c26ae20016627eccc0c017fab649a3b90e742069a2bd208aa525f8b4/asyncpg_lite-0.3.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bae19bad6b01339b4021bbbe048ea51cf9abd41d363b7213c414dd2a9a2f74db",
"md5": "054c66db6cbff24d4e23b4f528db4a00",
"sha256": "c9a4f5d23033e28aed484f409e8c677ef4dd5f583a34b12ad4e20fd4b2e66874"
},
"downloads": -1,
"filename": "asyncpg_lite-0.3.1.3.tar.gz",
"has_sig": false,
"md5_digest": "054c66db6cbff24d4e23b4f528db4a00",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 6600,
"upload_time": "2024-06-20T20:06:00",
"upload_time_iso_8601": "2024-06-20T20:06:00.565091Z",
"url": "https://files.pythonhosted.org/packages/ba/e1/9bad6b01339b4021bbbe048ea51cf9abd41d363b7213c414dd2a9a2f74db/asyncpg_lite-0.3.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-20 20:06:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Yakvenalex",
"github_project": "asyncpg_lite",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "asyncpg-lite"
}