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.6.tar.gz
(10.5 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_validation-1.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1b9bf0a565d9b6f8769224556eaf0f1e80986d425c0764cad8743e1f3231e8 |
|
MD5 | 164fcc89fa4192138a2b3e9dd60e9824 |
|
BLAKE2b-256 | 1dc066f387a110309911fffc818787cce949e2f83b77e2380e02fb001794efb9 |