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.8.tar.gz
(10.5 kB
view details)
Built Distribution
File details
Details for the file fastapi_validation-1.1.8.tar.gz
.
File metadata
- Download URL: fastapi_validation-1.1.8.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d99b31a5d281f6d0e337fd93333091bf40ca511359da7bd62a282465f796637 |
|
MD5 | 41398723d74fe0cfd405caa98858204c |
|
BLAKE2b-256 | eb723fd3b23b45436cb0a87bbb6cd7127aecf7f2cfb927a9a9ecd75426d848f0 |
File details
Details for the file fastapi_validation-1.1.8-py3-none-any.whl
.
File metadata
- Download URL: fastapi_validation-1.1.8-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4402d3660bcadcd109d9fa2de9a06120f098ce3f95d7f84d6df0001a0f8baa5 |
|
MD5 | cefaff0b8bca38654d9035798c20dc81 |
|
BLAKE2b-256 | 6bc91f4f9abc436d20bf2b7adbc53264dbe0fc3ef29c982cf906338eb20b614c |