File: test_update.py

package info (click to toggle)
sqlmodel 0.0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,344 kB
  • sloc: python: 16,107; javascript: 283; sh: 16; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 580 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from sqlmodel import Field, SQLModel


def test_sqlmodel_update():
    class Organization(SQLModel, table=True):
        id: int = Field(default=None, primary_key=True)
        name: str
        headquarters: str

    class OrganizationUpdate(SQLModel):
        name: str

    org = Organization(name="Example Org", city="New York", headquarters="NYC HQ")
    org_in = OrganizationUpdate(name="Updated org")
    org.sqlmodel_update(
        org_in,
        update={
            "headquarters": "-",  # This field is in Organization, but not in OrganizationUpdate
        },
    )