This release is a pre-release and may not be stable for production use.
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
Metadata
Release files for partial-table 0.0.1a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| partial_table-0.0.1a0.tar.gz | 2.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| partial_table-0.0.1a0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.2 kB
Release files / partial_table-0.0.1a0.tar.gz
| Download URL | partial_table-0.0.1a0.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d747f832934bcd6f20ba05cb42cb715024c363e94e314bff2c1fbf3d35fdc9de
|
|
BLAKE2b-256 checksum How to use checksums |
f71548dcf19b1bd86a76139b5a2dd970675513347524e4057336e3a7bc501bdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.10.11 Darwin/23.5.0
|
Release files / partial_table-0.0.1a0-py3-none-any.whl
| Download URL | partial_table-0.0.1a0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5943b349a468de8e07fc384eb8a475c8b34f218e82e6288038302fdd8e5bf0b
|
|
BLAKE2b-256 checksum How to use checksums |
2625c1ad4fe23cb4aedd1adc3b4be35aa7c928cebe765642e2c7d5c941a29c56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.10.11 Darwin/23.5.0
|
Security for partial-table 0.0.1a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.