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.2.tar.gz
(10.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_validation-1.1.2.tar.gz
.
File metadata
- Download URL: fastapi_validation-1.1.2.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 | d424b9fd5b8aba81c61945bf93fccc2f2709e7886a9ec9193c1450caedeffd97 |
|
MD5 | 1c7c7a11de19b7a8b0834a212c9de909 |
|
BLAKE2b-256 | 0db195a1644bae9fb53fe22a8f2fc7637958a316565cf018691093d38c8f1b9e |
File details
Details for the file fastapi_validation-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_validation-1.1.2-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 | 0fc556b0b4d0359f37000fdf5683d0f845f1727b014c4065dc3e2bc46a4f71cd |
|
MD5 | 7d917be5a06edf4d2ca0ce9ad45c0a46 |
|
BLAKE2b-256 | cf79b4a6df15dcae92e63b27207a21c6ca85a21684c63bd3d505975b3cfa8e8e |