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.7.tar.gz
(10.5 kB
view details)
Built Distribution
File details
Details for the file fastapi_validation-1.1.7.tar.gz
.
File metadata
- Download URL: fastapi_validation-1.1.7.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93273feccae8574d5e2691f9571b1ad4447855a671ca7cc179878b133a6fbb25 |
|
MD5 | 5407935e3ddfbb6ec55357b4e31c4e87 |
|
BLAKE2b-256 | 91ced4db4882bae08575de65dfaf3f7f0b44492f5cdfde0d2996500f5a6e8696 |
File details
Details for the file fastapi_validation-1.1.7-py3-none-any.whl
.
File metadata
- Download URL: fastapi_validation-1.1.7-py3-none-any.whl
- Upload date:
- Size: 11.3 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 | 75021bc58635645134082cc8966444a4177495f8ef149d988734a543e90a44c2 |
|
MD5 | 5122546b453cccc42cc2aedd674adfff |
|
BLAKE2b-256 | 2684d95dbe8a57686c28a3dd5fa6f9810f1b568f9fa86179d384e09245300176 |