![Logo](https://raw.githubusercontent.com/yezz123/ormdantic/main/.github/logo.png)
<p align="center">
<em>Asynchronous ORM that uses pydantic models to represent database tables ✨</em>
</p>
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 intuitive, easy to use, compatible, and robust.
**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)?
>
> PyPika is a Python API for building SQL queries. The motivation behind PyPika is to provide a simple interface for building SQL queries without limiting the flexibility of handwritten SQL. Designed with data analysis in mind, PyPika leverages the builder design pattern to construct queries to avoid messy string formatting and concatenation. It is also easily extended to take full advantage of specific features of SQL database vendors.
The key features are:
* **Easy to use**: It has sensible defaults and does a lot of work underneath to simplify the code you write.
* **Compatible**: 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.
* **Extensible**: You have all the power of SQLAlchemy and Pypika underneath.
* **Short Queries**: You can write queries in a single line of code, and it will be converted to the appropriate syntax for the database you are using.
Requirements
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 **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 Ormdantic in a few easy steps. First of all, install the dependency:
shell
$ pip install ormdantic
---> 100%
Successfully installed Ormdantic
* Install The specific Asynchronous ORM library for your database.
shell
MySQL
$ pip install ormdantic[mysql]
PostgreSQL
$ pip install ormdantic[postgres]
SQLite
$ pip install ormdantic[sqlite]
Example
To understand SQL, Sebastian the Creator of FastAPI and SQLModel created an amazing documentation that could help you understand the basics of SQL, ex. `CREATE TABLE`, `INSERT`, `SELECT`, `UPDATE`, `DELETE`, etc.
Check out the [documentation](https://sqlmodel.tiangolo.com/).
But let's see how to use Ormdantic.
Create SQLAlchemy 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 ormdantic import Ormdantic
engine = create_engine("sqlite+aiosqlite:///db.sqlite3")
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.
What's Changed
* Chore(feat): Improve many to many relationships & add New tests by yezz123 in https://github.com/yezz123/ormdantic/pull/15
**Full Changelog**: https://github.com/yezz123/ormdantic/compare/1.0.0...1.1.0