diff --git a/.github/logo.png b/.github/logo.png index add081f..0b9ef34 100644 Binary files a/.github/logo.png and b/.github/logo.png differ diff --git a/README.md b/README.md index 108128e..a8bc2d9 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,20 @@

- - lint + + lint - - Test + + Test - - Coverage + + Coverage

-PydanticORM is a library for interacting with Asynchronous SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, compatible, and robust. +Ormdantic is a library for interacting with Asynchronous SQL databases from Python code, with Python objects. It is designed to be intuitive, easy to use, compatible, and robust. -**PydanticORM** is based on [Pypika](https://github.com/kayak/pypika), and powered by Pydantic and SQLAlchemy, and Highly inspired by Sqlmodel, Created by [@tiangolo](https://github.com/tiangolo). +**Ormdantic** is based on [Pypika](https://github.com/kayak/pypika), and powered by Pydantic and SQLAlchemy, and Highly inspired by Sqlmodel, Created by [@tiangolo](https://github.com/tiangolo). > What is [Pypika](https://github.com/kayak/pypika)? > @@ -35,31 +35,31 @@ The key features are: A recent and currently supported version of Python (right now, Python supports versions 3.10 and above). -As **PydanticORM** is based on **Pydantic** and **SQLAlchemy** and **Pypika**, it requires them. They will be automatically installed when you install PydanticORM. +As **Ormdantic** is based on **Pydantic** and **SQLAlchemy** and **Pypika**, it requires them. They will be automatically installed when you install Ormdantic. ## Installation -You can add PydanticORM in a few easy steps. First of all, install the dependency: +You can add Ormdantic in a few easy steps. First of all, install the dependency: ```shell -$ pip install pydantic_orm +$ pip install ormdantic ---> 100% -Successfully installed PydanticORM +Successfully installed Ormdantic ``` * Install The specific Asynchronous ORM library for your database. ```shell # MySQL -$ pip install pydantic_orm[mysql] +$ pip install ormdantic[mysql] # PostgreSQL -$ pip install pydantic_orm[postgres] +$ pip install ormdantic[postgres] # SQLite -$ pip install pydantic_orm[sqlite] +$ pip install ormdantic[sqlite] ``` ## Example @@ -68,18 +68,18 @@ To understand SQL, Sebastian the Creator of FastAPI and SQLModel created an amaz Check out the [documentation](https://sqlmodel.tiangolo.com/). -But let's see how to use PydanticORM. +But let's see how to use Ormdantic. ### Create SQLAlchemy engine -PydanticORM uses SQLAlchemy under hood to run different queries, which is why we need to initialize by creating an asynchronous engine. +Ormdantic uses SQLAlchemy under hood to run different queries, which is why we need to initialize by creating an asynchronous engine. ```python from sqlalchemy.ext.asyncio import create_async_engine as create_engine -from pydantic_orm import PydanticORM +from ormdantic import Ormdantic engine = create_engine("sqlite+aiosqlite:///db.sqlite3") -database = PydanticORM(engine) +database = Ormdantic(engine) ``` **Note**: You can use any asynchronous engine, check out the [documentation](https://docs.sqlalchemy.org/en/14/core/engines.html) for more information. @@ -104,7 +104,7 @@ class Flavor(BaseModel): Now after we create the table, we can initialize the database with the table and then run different queries. -#### [`Init()`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/orm.py#L67) +#### [`Init()`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/orm.py#L67) * Register models as ORM models and initialize the database. @@ -115,7 +115,7 @@ async def main() -> None: await database.init() ``` -#### [`Insert()`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L59) +#### [`Insert()`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L59) Now let's imagine we have another table called `Coffee` that has a foreign key to `Flavor`. @@ -150,9 +150,9 @@ await database[Coffee].insert(coffee) As we know, in SQL, we can search for data using different methods, ex. `WHERE`, `LIKE`, `IN`, `BETWEEN`, etc. -In PydanticORM, we can search for data using the `database.find_one` or `database.find_many` methods. +In Ormdantic, we can search for data using the `database.find_one` or `database.find_many` methods. -* [`Find_one`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L35) used to find a Model instance by Primary Key, its could also find with `depth` parameter. +* [`Find_one`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L35) used to find a Model instance by Primary Key, its could also find with `depth` parameter. ```python # Find one @@ -164,7 +164,7 @@ In PydanticORM, we can search for data using the `database.find_one` or `databas print(find_coffee.flavor.name) ``` -* [`Find_many`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L39) used to find Model instances by some condition ex. `where`, `order_by`, `order`, `limit`, `offset`, `depth`. +* [`Find_many`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L39) used to find Model instances by some condition ex. `where`, `order_by`, `order`, `limit`, `offset`, `depth`. ```python # Find many @@ -176,7 +176,7 @@ In PydanticORM, we can search for data using the `database.find_one` or `databas ) ``` -#### [`Update`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L65) / [`Upsert`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L71) Queries +#### [`Update`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L65) / [`Upsert`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L71) Queries ##### Update @@ -198,7 +198,7 @@ The `Upsert` method is similar to the Synchronize method with one exception; the await database[Flavor].upsert(flavor) ``` -### [`Delete`](https://github.com/yezz123/PydanticORM/blob/400ecfde754fc6613923779a6a545a0f00282752/pydantic_orm/generator/_crud.py#L77) +### [`Delete`](https://github.com/yezz123/ormdantic/blob/400ecfde754fc6613923779a6a545a0f00282752/ormdantic/generator/_crud.py#L77) The `DELETE` statement is used to delete existing records in a table. diff --git a/pydantic_orm/__init__.py b/ormdantic/__init__.py similarity index 61% rename from pydantic_orm/__init__.py rename to ormdantic/__init__.py index 32ba249..5f2de3f 100644 --- a/pydantic_orm/__init__.py +++ b/ormdantic/__init__.py @@ -2,6 +2,6 @@ __version__ = "1.0.0" -from pydantic_orm.orm import PydanticORM +from ormdantic.orm import Ormdantic -__all__ = ["PydanticORM"] +__all__ = ["Ormdantic"] diff --git a/ormdantic/generator/__init__.py b/ormdantic/generator/__init__.py new file mode 100644 index 0000000..4adb58e --- /dev/null +++ b/ormdantic/generator/__init__.py @@ -0,0 +1,4 @@ +from ormdantic.generator._crud import PydanticSQLCRUDGenerator as CRUD +from ormdantic.generator._table import PydanticSQLTableGenerator as Table + +__all__ = ["Table", "CRUD"] diff --git a/pydantic_orm/generator/_crud.py b/ormdantic/generator/_crud.py similarity index 99% rename from pydantic_orm/generator/_crud.py rename to ormdantic/generator/_crud.py index e4027ff..6f30c09 100644 --- a/pydantic_orm/generator/_crud.py +++ b/ormdantic/generator/_crud.py @@ -14,9 +14,9 @@ from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession from sqlalchemy.orm import sessionmaker -from pydantic_orm.handler import TableName_From_Model -from pydantic_orm.table import PydanticTableMeta, Relation, RelationType, Result -from pydantic_orm.types import ModelType +from ormdantic.handler import TableName_From_Model +from ormdantic.table import PydanticTableMeta, Relation, RelationType, Result +from ormdantic.types import ModelType class PydanticSQLCRUDGenerator(Generic[ModelType]): diff --git a/pydantic_orm/generator/_table.py b/ormdantic/generator/_table.py similarity index 97% rename from pydantic_orm/generator/_table.py rename to ormdantic/generator/_table.py index 606275b..10fa5b6 100644 --- a/pydantic_orm/generator/_table.py +++ b/ormdantic/generator/_table.py @@ -19,8 +19,8 @@ from sqlalchemy.dialects import postgresql from sqlalchemy.ext.asyncio import AsyncEngine -from pydantic_orm.handler import TableName_From_Model, TypeConversionError -from pydantic_orm.table import PydanticTableMeta, RelationType +from ormdantic.handler import TableName_From_Model, TypeConversionError +from ormdantic.table import PydanticTableMeta, RelationType class PydanticSQLTableGenerator: diff --git a/pydantic_orm/handler/__init__.py b/ormdantic/handler/__init__.py similarity index 68% rename from pydantic_orm/handler/__init__.py rename to ormdantic/handler/__init__.py index ceac499..8b95994 100644 --- a/pydantic_orm/handler/__init__.py +++ b/ormdantic/handler/__init__.py @@ -1,12 +1,12 @@ -from pydantic_orm.handler.errors import ( +from ormdantic.handler.errors import ( ConfigurationError, MismatchingBackReferenceError, MustUnionForeignKeyError, TypeConversionError, UndefinedBackReferenceError, ) -from pydantic_orm.handler.helper import Get_M2M_TableName, TableName_From_Model -from pydantic_orm.handler.snake import snake as snake_case +from ormdantic.handler.helper import Get_M2M_TableName, TableName_From_Model +from ormdantic.handler.snake import snake as snake_case __all__ = [ "TableName_From_Model", diff --git a/pydantic_orm/handler/errors.py b/ormdantic/handler/errors.py similarity index 100% rename from pydantic_orm/handler/errors.py rename to ormdantic/handler/errors.py diff --git a/pydantic_orm/handler/helper.py b/ormdantic/handler/helper.py similarity index 93% rename from pydantic_orm/handler/helper.py rename to ormdantic/handler/helper.py index 9cbf5d8..227dac4 100644 --- a/pydantic_orm/handler/helper.py +++ b/ormdantic/handler/helper.py @@ -1,7 +1,7 @@ """Utility functions used throughout the project.""" from typing import Any, Type -from pydantic_orm.types import ModelType +from ormdantic.types import ModelType def TableName_From_Model(model: Type[ModelType], schema: dict[str, Any]) -> str: diff --git a/pydantic_orm/handler/snake.py b/ormdantic/handler/snake.py similarity index 100% rename from pydantic_orm/handler/snake.py rename to ormdantic/handler/snake.py diff --git a/pydantic_orm/orm.py b/ormdantic/orm.py similarity index 96% rename from pydantic_orm/orm.py rename to ormdantic/orm.py index 9daae45..7c3591c 100644 --- a/pydantic_orm/orm.py +++ b/ormdantic/orm.py @@ -6,19 +6,19 @@ from sqlalchemy import MetaData from sqlalchemy.ext.asyncio import AsyncEngine -from pydantic_orm.generator import CRUD, Table -from pydantic_orm.handler import ( +from ormdantic.generator import CRUD, Table +from ormdantic.handler import ( Get_M2M_TableName, MismatchingBackReferenceError, MustUnionForeignKeyError, UndefinedBackReferenceError, snake_case, ) -from pydantic_orm.table import PydanticTableMeta, Relation, RelationType -from pydantic_orm.types import ModelType +from ormdantic.table import PydanticTableMeta, Relation, RelationType +from ormdantic.types import ModelType -class PydanticORM: +class Ormdantic: """ It combines SQLAlchemy, Pydantic and Pypika tries to simplify the code you write as much as possible, allowing you to reduce the code duplication to a minimum, but while getting the best developer experience possible. diff --git a/pydantic_orm/py.typed b/ormdantic/py.typed similarity index 100% rename from pydantic_orm/py.typed rename to ormdantic/py.typed diff --git a/pydantic_orm/table.py b/ormdantic/table.py similarity index 96% rename from pydantic_orm/table.py rename to ormdantic/table.py index 26b6d15..8353ec7 100644 --- a/pydantic_orm/table.py +++ b/ormdantic/table.py @@ -5,7 +5,7 @@ from pydantic import BaseModel from pydantic.generics import GenericModel -from pydantic_orm.types import ModelType +from ormdantic.types import ModelType class RelationType(Enum): diff --git a/pydantic_orm/types/__init__.py b/ormdantic/types/__init__.py similarity index 63% rename from pydantic_orm/types/__init__.py rename to ormdantic/types/__init__.py index 7001d39..00c3bbd 100644 --- a/pydantic_orm/types/__init__.py +++ b/ormdantic/types/__init__.py @@ -1,5 +1,5 @@ """Provides ModelType TypeVar used throughout lib.""" -from pydantic_orm.types.base import ModelType +from ormdantic.types.base import ModelType __all__ = ["ModelType"] diff --git a/pydantic_orm/types/base.py b/ormdantic/types/base.py similarity index 100% rename from pydantic_orm/types/base.py rename to ormdantic/types/base.py diff --git a/pydantic_orm/generator/__init__.py b/pydantic_orm/generator/__init__.py deleted file mode 100644 index b466660..0000000 --- a/pydantic_orm/generator/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from pydantic_orm.generator._crud import PydanticSQLCRUDGenerator as CRUD -from pydantic_orm.generator._table import PydanticSQLTableGenerator as Table - -__all__ = ["Table", "CRUD"] diff --git a/pyproject.toml b/pyproject.toml index a7a7471..4fff9a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,11 +3,11 @@ requires = ["flit"] build-backend = "flit.buildapi" [tool.flit.metadata] -module = "pydantic_orm" -dist-name = "pydantic_orm" +module = "ormdantic" +dist-name = "ormdantic" author = "Yasser Tahiri" author-email = "hello@yezz.me" -home-page = "https://github.com/yezz123/PydanticORM" +home-page = "https://github.com/yezz123/ormdantic" classifiers = [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", diff --git a/scripts/lint.sh b/scripts/lint.sh index cdf7286..405d83b 100644 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -3,4 +3,4 @@ set -e set -x -mypy --show-error-codes pydantic_orm tests \ No newline at end of file +mypy --show-error-codes ormdantic tests \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh index b95025b..ef65fdc 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -6,4 +6,4 @@ set -x echo "ENV=${ENV}" export PYTHONPATH=. -pytest --cov=pydantic_orm --cov=tests \ No newline at end of file +pytest --cov=ormdantic --cov=tests \ No newline at end of file diff --git a/scripts/test_html.sh b/scripts/test_html.sh index 9d209cf..d92e5c4 100644 --- a/scripts/test_html.sh +++ b/scripts/test_html.sh @@ -6,4 +6,4 @@ set -x echo "ENV=${ENV}" export PYTHONPATH=. -pytest --cov=pydantic_orm --cov=tests --cov-report=html \ No newline at end of file +pytest --cov=ormdantic --cov=tests --cov-report=html \ No newline at end of file diff --git a/tests/test_errors.py b/tests/test_errors.py index f4f1c9d..2b3cbdc 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -10,8 +10,8 @@ from sqlalchemy import MetaData from sqlalchemy.ext.asyncio import create_async_engine -from pydantic_orm import PydanticORM -from pydantic_orm.handler import ( +from ormdantic import Ormdantic +from ormdantic.handler import ( MismatchingBackReferenceError, MustUnionForeignKeyError, TypeConversionError, @@ -21,11 +21,11 @@ URL = config("DATABASE_URL") engine = create_async_engine(URL) -db_1 = PydanticORM(engine) -db_2 = PydanticORM(engine) -db_3 = PydanticORM(engine) -db_4 = PydanticORM(engine) -db_5 = PydanticORM(engine) +db_1 = Ormdantic(engine) +db_2 = Ormdantic(engine) +db_3 = Ormdantic(engine) +db_4 = Ormdantic(engine) +db_5 = Ormdantic(engine) @db_1.table(pk="id") @@ -95,7 +95,7 @@ class Table_5(BaseModel): UndefinedBackreference.update_forward_refs() -class PydanticORMErrorTesting(unittest.IsolatedAsyncioTestCase): +class ormdanticErrorTesting(unittest.IsolatedAsyncioTestCase): def setUp(self) -> None: """Setup clean sqlite database.""" diff --git a/tests/test_orm.py b/tests/test_orm.py index a86c6fb..0f64f52 100644 --- a/tests/test_orm.py +++ b/tests/test_orm.py @@ -9,12 +9,12 @@ from pypika import Order from sqlalchemy.ext.asyncio import create_async_engine -from pydantic_orm import PydanticORM +from ormdantic import Ormdantic URL = config("DATABASE_URL") engine = create_async_engine(URL) -database = PydanticORM(engine) +database = Ormdantic(engine) class Money(BaseModel): @@ -63,7 +63,7 @@ class Table(BaseModel): Flavor.update_forward_refs() -class PydanticORMTesting(unittest.IsolatedAsyncioTestCase): +class ormdanticTesting(unittest.IsolatedAsyncioTestCase): def setUp(self) -> None: """Setup clean sqlite database.""" diff --git a/tests/test_otm_relations.py b/tests/test_otm_relations.py index 2d8d9da..67f8b0f 100644 --- a/tests/test_otm_relations.py +++ b/tests/test_otm_relations.py @@ -8,12 +8,12 @@ from pydantic import BaseModel, Field from sqlalchemy.ext.asyncio import create_async_engine -from pydantic_orm import PydanticORM +from ormdantic import Ormdantic URL = config("DATABASE_URL") engine = create_async_engine(URL) -database = PydanticORM(engine) +database = Ormdantic(engine) @database.table(pk="id", back_references={"many_a": "one_a", "many_b": "one_b"}) @@ -38,7 +38,7 @@ class Many(BaseModel): Many.update_forward_refs() -class PydanticORMOneToManyRelationTesting(unittest.IsolatedAsyncioTestCase): +class ormdanticOneToManyRelationTesting(unittest.IsolatedAsyncioTestCase): def setUp(self) -> None: """Setup clean sqlite database.""" diff --git a/tests/test_version.py b/tests/test_version.py index 30aefff..88c01be 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,5 +1,5 @@ -import pydantic_orm +import ormdantic def test_version() -> None: - assert pydantic_orm.__version__ == "1.0.0" + assert ormdantic.__version__ == "1.0.0"