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.11.tar.gz
(10.5 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_validation-1.1.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d160a9e88acd8ae4ec3af0a5ef8d0eb7d7ec82b46859fef2d7edfbb6003284 |
|
MD5 | 3f5ccda32a2334940455eeea5040bcdb |
|
BLAKE2b-256 | 40ad1a43650790e4f467114bb13e95a646b6882486029cd0640df1fadb2bfb40 |
Close
Hashes for fastapi_validation-1.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcc15ef94a2731792afbfb5dc733bfe3a81e9680b2d2a7689838287e5193411c |
|
MD5 | 8d66c018102bbc927de4246f79760ab9 |
|
BLAKE2b-256 | 549a970153bf102853774e2d8490a8ed742e2b9021598b93d1723f525a4e0715 |