Skip to content

Commit

Permalink
🔧 chore(feat): Update Repo's name (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 authored Aug 22, 2022
1 parent 7855548 commit 0a717fd
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 70 deletions.
Binary file modified .github/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
</p>

<p align="center">
<a href="https://github.com/yezz123/PydanticORM/actions/workflows/lint.yml" target="_blank">
<img src="https://github.com/yezz123/PydanticORM/actions/workflows/lint.yml/badge.svg" alt="lint">
<a href="https://github.com/yezz123/ormdantic/actions/workflows/lint.yml" target="_blank">
<img src="https://github.com/yezz123/ormdantic/actions/workflows/lint.yml/badge.svg" alt="lint">
</a>
<a href="https://github.com/yezz123/PydanticORM/actions/workflows/test.yml" target="_blank">
<img src="https://github.com/yezz123/PydanticORM/actions/workflows/test.yml/badge.svg" alt="Test">
<a href="https://github.com/yezz123/ormdantic/actions/workflows/test.yml" target="_blank">
<img src="https://github.com/yezz123/ormdantic/actions/workflows/test.yml/badge.svg" alt="Test">
</a>
<a href="https://codecov.io/gh/yezz123/PydanticORM" target="_blank">
<img src="https://img.shields.io/codecov/c/github/yezz123/PydanticORM?color=%2334D058" alt="Coverage">
<a href="https://codecov.io/gh/yezz123/ormdantic" target="_blank">
<img src="https://img.shields.io/codecov/c/github/yezz123/ormdantic?color=%2334D058" alt="Coverage">
</a>
</p>

PydanticORM is a library for interacting with Asynchronous <abbr title='Also called "Relational databases"'>SQL databases</abbr> 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 <abbr title='Also called "Relational databases"'>SQL databases</abbr> 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 <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> and <a href="https://sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a>, and Highly inspired by <a href="https://github.com/tiangolo/Sqlmodel" class="external-link" target="_blank">Sqlmodel</a>, Created by [@tiangolo](https://github.com/tiangolo).
**Ormdantic** is based on [Pypika](https://github.com/kayak/pypika), and powered by <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> and <a href="https://sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a>, and Highly inspired by <a href="https://github.com/tiangolo/Sqlmodel" class="external-link" target="_blank">Sqlmodel</a>, Created by [@tiangolo](https://github.com/tiangolo).

> What is [Pypika](https://github.com/kayak/pypika)?
>
Expand All @@ -35,31 +35,31 @@ The key features are:

A recent and currently supported version of Python (right now, <a href="https://www.python.org/downloads/" class="external-link" target="_blank">Python supports versions 3.10 and above</a>).

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
Expand All @@ -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.
Expand All @@ -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.

Expand All @@ -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`.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions pydantic_orm/__init__.py → ormdantic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__version__ = "1.0.0"

from pydantic_orm.orm import PydanticORM
from ormdantic.orm import Ormdantic

__all__ = ["PydanticORM"]
__all__ = ["Ormdantic"]
4 changes: 4 additions & 0 deletions ormdantic/generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ormdantic.generator._crud import PydanticSQLCRUDGenerator as CRUD
from ormdantic.generator._table import PydanticSQLTableGenerator as Table

__all__ = ["Table", "CRUD"]
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions pydantic_orm/orm.py → ormdantic/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pydantic_orm/table.py → ormdantic/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
4 changes: 0 additions & 4 deletions pydantic_orm/generator/__init__.py

This file was deleted.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e
set -x

mypy --show-error-codes pydantic_orm tests
mypy --show-error-codes ormdantic tests
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -x
echo "ENV=${ENV}"

export PYTHONPATH=.
pytest --cov=pydantic_orm --cov=tests
pytest --cov=ormdantic --cov=tests
2 changes: 1 addition & 1 deletion scripts/test_html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -x
echo "ENV=${ENV}"

export PYTHONPATH=.
pytest --cov=pydantic_orm --cov=tests --cov-report=html
pytest --cov=ormdantic --cov=tests --cov-report=html
16 changes: 8 additions & 8 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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."""

Expand Down
6 changes: 3 additions & 3 deletions tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""

Expand Down
6 changes: 3 additions & 3 deletions tests/test_otm_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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."""

Expand Down
4 changes: 2 additions & 2 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0a717fd

Please sign in to comment.