Partial Table Models for SQLAlchemy
Project description
SQLAlchemy Partial Tables
Partial Tables for SQLAlchemy
Installation
pip install partial-table
Scenario
Let's say you have 2 tables, business_draft and business.
business_draft and business have the same fields, but business_draft should allow most fields to be nullable.
Any business can freely update its draft, but only approved modifications get copied over to business.
How can we implement this and reduce redundancy?
Usage
Any field marked with PartialAllowed will be nullable in the partial table, and required in the complete table.
Example
from typing import Annotated
from abc import ABC
from sqlmodel import Field, SQLModel
from partial_table import PartialBase, PartialAllowed, PartialTable
class Base(ABC, SQLModel):
"""Base class for all models."""
id: int = Field(primary_key=True, sa_column_kwargs={"autoincrement": True})
class BusinessBase(PartialBase, Base):
"""Base class for all business models."""
business_name: str
city: Annotated[str, PartialAllowed()] = Field()
address: Annotated[str, PartialAllowed()] = Field()
class BusinessDraft(BusinessBase, PartialTable, table=True):
__tablename__ = "business_draft"
class Business(BusinessBase, table=True):
__tablename__ = "business"
Business has all required fields, and BusinessDraft has every field marked with PartialAllowed as nullable.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file partial_tables-0.0.1a1.tar.gz.
File metadata
- Download URL: partial_tables-0.0.1a1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
207624e92c35d246e36b32d0824276e25aa8d3a02a096a4369fb2f9242be9bdc
|
|
| MD5 |
56441b8fca43cabb2ed4ffea451536ae
|
|
| BLAKE2b-256 |
18133b6a296693727dc82fb8ddafe6b1db8e94bf17317b5dfe7fcf70dc83bcc8
|
File details
Details for the file partial_tables-0.0.1a1-py3-none-any.whl.
File metadata
- Download URL: partial_tables-0.0.1a1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c4f168f046ffc6c6872dd4e446769935e163aeb19add951c7aee26764c876a9
|
|
| MD5 |
9ef533f13a3d18a94b7463cf48c975ed
|
|
| BLAKE2b-256 |
f83a6ce9e78aa4629e0553904af71390a230f9dcd37747561d546a73af800fe0
|