FastAPI Event
Project description
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
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
GlobalVariable.set('database_type', DatabaseTypeEnum.NOSQL) # We can skip this line because the defautl database_type is SQL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_validation-1.1.4.tar.gz
(10.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_validation-1.1.4.tar.gz
.
File metadata
- Download URL: fastapi_validation-1.1.4.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7b38110907c4e4b589e3cf82d8a47629da18bdeec827398a49512030e8d33d2 |
|
MD5 | a34e193fd8b4768c0d58f926403ef6f2 |
|
BLAKE2b-256 | 20d9fd1f30be704645dd044096163bc5c10e81d40e97b4279e346dcbf2dffd75 |
File details
Details for the file fastapi_validation-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: fastapi_validation-1.1.4-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be511504546f0633461e7d7dc060e24f87d7152a42748e44de8eaa0bc0411426 |
|
MD5 | 32a4dde43887ce534a7526b18d2e56d4 |
|
BLAKE2b-256 | 76c6a2b6db37679e63697fc6c069b9ea0eac3d2c1a54a47a180bca618014172d |