Metadata-Version: 2.3
Name: fastapi_validation
Version: 1.1.15
Summary: FastAPI Event
Project-URL: Homepage, https://github.com/megatron-global/fastapi-validation
Project-URL: Bug Tracker, https://github.com/megatron-global/fastapi-validation/issues
Author-email: Dzung Nguyen <dung@megatron-solutions.com>, Harry Dang <harrydang.tech@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: beanie>=1.21.0
Requires-Dist: fastapi-exception>=1.3.0
Requires-Dist: fastapi-global-variable>=0.0.4
Requires-Dist: pydantic>=2.6.0
Requires-Dist: python-keycloak~=2.14.0
Requires-Dist: sqlalchemy~=2.0.4
Description-Content-Type: text/markdown

# FastAPI Validation

FastAPI Validation support both SQLAlchemy for sql database and BeanieODM for nosql Database.
To use the @Exists and @Unique decorator we need to set global-variable for the database_type
Check the sample code below

## For SQL Database using SQLAlchemy as ORM

```python
from fastapi_validation import DatabaseTypeEnum

engine = create_engine(SQLALCHEMY_DATABASE_URL, echo=False, pool_size=50, max_overflow=100)
global_db_session: Session = sessionmaker(
    autoflush=False, autobegin=True, bind=engine, join_transaction_mode='rollback_only'
)()
def run_with_global_session(callback):
    try:
        return callback(global_db_session)
    except Exception as e:
        global_db_session.rollback()
        raise e

GlobalVariable.set('run_with_global_session', run_with_global_session)
GlobalVariable.set('database_type', DatabaseTypeEnum.SQL)
```

## For Nosql Database using Beanie as ODM

```python
GlobalVariable.set('database_type', DatabaseTypeEnum.NOSQL) # We can skip this line because the defautl database_type is SQL

```
