# AlchemyLite
## A library that simplifies CRUD operations with PostgreSQL database.
# How to use it?
First you need to create a configuration in which you need to register the database parameters
For synchronous operation
```pythonregexp
from alchemylite.sync impoty SyncConfig
config = SyncConfig(
db_host="your_host",
db_port="your_port",
db_user="your_user",
db_pass="your_password",
db_name="your_db_name"
)
```
Then, we create a class to which we pass our configuration, model class and base class of model
```pythonregexp
from alchemylite.sync import SyncCrudOperation
crud = SyncCrudOperation(
config.session, YourModel, Base
)
```
For async operation
```pythonregexp
from alchemylite.async_ import AsyncConfig, AsyncCrudOperation
config = AsyncConfig(
db_host="your_host",
db_port="your_port",
db_user="your_user",
db_pass="your_password",
db_name="your_db_name"
)
crud = AsyncCrudOperation(
config.session, YourModel, Base
)
```
If you have your session, you don't need to create config class, just transfer your session
```pythonregexp
crud = AsyncCrudOperation(
your_session, YourModel, Base
)
```
# How to perform CRUD operations?
The library supports the following methods
* create - Creates new data in the table.
* read_all - Reads all data from a table.
* limited_read - Reads a certain amount of data. Default values: limit = 50, offset = 0
* read_by_id - Reads all data from a table by id
* update_by_id - Update data by id
* delete_by_id - Delete data by id
* create_all_tables - Creates all tables in database
* delete_all_tables - Delete all tables in database
# Examples of use
```pythonregexp
from alchemylite.sync import SyncCrudOperation, SyncConfig
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase
config = SyncConfig(
db_host="localhost",
db_port="5432",
db_user="postgres",
db_pass="postgres",
db_name="alchemylite"
)
class Base(DeclarativeBase):
pass
class User(Base):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
email: Mapped[str]
crud = SyncCrudOperation(
config.session, User, Base
)
crud.create_all_tables()
crud.create(name="User", email="email@mail.ru")
crud.read_all()
crud.limited_read(limit=5, offset=0)
crud.read_by_id(id=1)
crud.update_by_id(id=1, name="new value", email="new_emal")
crud.delete_by_id(id=1)
crud.delete_all_tables()
```
## The library will be supported, this is the first version for now. New features will be added in the future.
### If you have suggestions for improvements or any comments, I'm ready to listen to you
Raw data
{
"_id": null,
"home_page": "https://github.com/voskanyan777/alchemylite",
"name": "AlchemyLite",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "alchemylite crud_sqlalchemy sqlalchemy",
"author": "voskan",
"author_email": "yura.voskanyan.2003@mail.ru",
"download_url": "https://files.pythonhosted.org/packages/66/1b/fc18bbf7e974c5287208bb6694c8801166152082e10f2cfdac86e85f2e6e/AlchemyLite-1.0.1.tar.gz",
"platform": null,
"description": "# AlchemyLite\r\n## A library that simplifies CRUD operations with PostgreSQL database.\r\n\r\n# How to use it?\r\nFirst you need to create a configuration in which you need to register the database parameters \r\nFor synchronous operation\r\n```pythonregexp\r\nfrom alchemylite.sync impoty SyncConfig\r\n\r\nconfig = SyncConfig(\r\n db_host=\"your_host\",\r\n db_port=\"your_port\",\r\n db_user=\"your_user\",\r\n db_pass=\"your_password\",\r\n db_name=\"your_db_name\"\r\n)\r\n```\r\nThen, we create a class to which we pass our configuration, model class and base class of model\r\n```pythonregexp\r\nfrom alchemylite.sync import SyncCrudOperation\r\n\r\ncrud = SyncCrudOperation(\r\n config.session, YourModel, Base\r\n)\r\n```\r\nFor async operation\r\n```pythonregexp\r\nfrom alchemylite.async_ import AsyncConfig, AsyncCrudOperation\r\n\r\nconfig = AsyncConfig(\r\n db_host=\"your_host\",\r\n db_port=\"your_port\",\r\n db_user=\"your_user\",\r\n db_pass=\"your_password\",\r\n db_name=\"your_db_name\"\r\n)\r\n\r\ncrud = AsyncCrudOperation(\r\n config.session, YourModel, Base\r\n)\r\n```\r\nIf you have your session, you don't need to create config class, just transfer your session\r\n```pythonregexp\r\ncrud = AsyncCrudOperation(\r\n your_session, YourModel, Base\r\n)\r\n``` \r\n# How to perform CRUD operations?\r\nThe library supports the following methods\r\n* create - Creates new data in the table.\r\n* read_all - Reads all data from a table.\r\n* limited_read - Reads a certain amount of data. Default values: limit = 50, offset = 0\r\n* read_by_id - Reads all data from a table by id\r\n* update_by_id - Update data by id\r\n* delete_by_id - Delete data by id\r\n* create_all_tables - Creates all tables in database\r\n* delete_all_tables - Delete all tables in database\r\n\r\n# Examples of use\r\n\r\n```pythonregexp\r\nfrom alchemylite.sync import SyncCrudOperation, SyncConfig\r\nfrom sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase\r\n\r\n\r\nconfig = SyncConfig(\r\n db_host=\"localhost\",\r\n db_port=\"5432\",\r\n db_user=\"postgres\",\r\n db_pass=\"postgres\",\r\n db_name=\"alchemylite\"\r\n)\r\n\r\n\r\nclass Base(DeclarativeBase):\r\n pass\r\n \r\n \r\nclass User(Base):\r\n id: Mapped[int] = mapped_column(primary_key=True)\r\n name: Mapped[str]\r\n email: Mapped[str]\r\n \r\n\r\ncrud = SyncCrudOperation(\r\n config.session, User, Base\r\n)\r\n\r\ncrud.create_all_tables()\r\ncrud.create(name=\"User\", email=\"email@mail.ru\")\r\ncrud.read_all()\r\ncrud.limited_read(limit=5, offset=0)\r\ncrud.read_by_id(id=1)\r\ncrud.update_by_id(id=1, name=\"new value\", email=\"new_emal\")\r\ncrud.delete_by_id(id=1)\r\ncrud.delete_all_tables()\r\n```\r\n## The library will be supported, this is the first version for now. New features will be added in the future.\r\n### If you have suggestions for improvements or any comments, I'm ready to listen to you\r\n\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Library with built-in CRUD operations in SQLAlchemy",
"version": "1.0.1",
"project_urls": {
"Documentation": "https://github.com/voskanyan777/alchemylite",
"Homepage": "https://github.com/voskanyan777/alchemylite"
},
"split_keywords": [
"alchemylite",
"crud_sqlalchemy",
"sqlalchemy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce6f15ab5c2ca7a54f49d5195cdd13d2985bbec7549043d3003008d0bcb1627c",
"md5": "663703e36d9035e48a04b513e2f55f73",
"sha256": "18fcd782861256f03864c60af61e3361c864fb82a51fc8c2d193fca77702bb97"
},
"downloads": -1,
"filename": "AlchemyLite-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "663703e36d9035e48a04b513e2f55f73",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 8269,
"upload_time": "2024-11-05T07:48:04",
"upload_time_iso_8601": "2024-11-05T07:48:04.648065Z",
"url": "https://files.pythonhosted.org/packages/ce/6f/15ab5c2ca7a54f49d5195cdd13d2985bbec7549043d3003008d0bcb1627c/AlchemyLite-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "661bfc18bbf7e974c5287208bb6694c8801166152082e10f2cfdac86e85f2e6e",
"md5": "0f0f96571010670b0470c53f82aefda6",
"sha256": "b7d4a87dd2d6db34c2c5a3c89cf270c61d48968fe8a99aa2d82a3cd68d095cd9"
},
"downloads": -1,
"filename": "AlchemyLite-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "0f0f96571010670b0470c53f82aefda6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 5701,
"upload_time": "2024-11-05T07:48:05",
"upload_time_iso_8601": "2024-11-05T07:48:05.640994Z",
"url": "https://files.pythonhosted.org/packages/66/1b/fc18bbf7e974c5287208bb6694c8801166152082e10f2cfdac86e85f2e6e/AlchemyLite-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-05 07:48:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "voskanyan777",
"github_project": "alchemylite",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "alchemylite"
}