Skip to main content

Use SQLAlchemy with Ex-DRF.

Project description

SqlAlchemy Support for Ex-DRF

The library provides guidance and support code for using SQLAlchemy with Ex-DRF.

Usage

Start by basing your models off Base from exdrf_al.base module. It is a rather simple class that allows for model andd fields iteration. If you don't want to use it, take a look at the implementation of that class for how to extract the information you need from your models.

Models

The library reads the description of models from the sqlAlchemy metadata. On top of that you cad add additional information by adding members to the info key in the __table_args__ model attribute.

The keys that are used inside the info dictionary are documented in exdrf.resource.ResExtraInfo, which is the pydantic class that parses the information. Here is brief description of the most important keys:

  • label: takes a string that is interpreted by the DSL in exdrf. label_dsl; it is used to generate code that computes the label of a record given the record. The exdrf.label_dsl module includes code to create python and typescript code from a parsed label definition.

Example:

class Example(Base):
    __tablename__ = "the_table"
    __table_args__ = {
        "info": {
            "label": """(if name name (concat "ID:" " id))""",
        }
    }
    id: int
    name: Optional[str] = None

Fields

Just like with the models, the model field metadata is used to extract the information. Additionally, we use values in the dictionary assigned to the info attribute to add additional information.

The keys that are used inside the info consist of a common subset for all field types and specific keys for each field type. The common keys parsed by the exdrf.field.FieldInfo class are documented with that class, and each field type is described in its own module under exdrf.field_types.

Example:

class Example(Base):
    __tablename__ = "the_table"
    id: Mapped[int] = mapped_column(
        primary_key=True,
        doc="The unique identifier for a record within its table",
        info={
            "sortable": False
        }
    )
    name: Mapped[Optional[str]] = mapped_column(
        doc="The name of the record",
        info={
            "filterable": False,
            "multiline": True,
            "min_length": 3,
        }
    )

Relationships

relationship(..., info={...}) is validated with exdrf.field_types.ref_base.RelExtraInfo, which extends exdrf.field.FieldInfo. Keys such as direction and doc are required or conventional; optional keys from FieldInfo apply as well.

When use_rel is true on a non-bridge OneToMany relationship, Qt code generation (exdrf-gen-al2qt) emits a dedicated editor tab with a DrfRelated-style transfer list (Qt{Parent}Rel{Ref}) instead of an inline Qt{Ref}MuSe control on category tabs.

Example:

items: Mapped[Set["Item"]] = relationship(
    "Item",
    back_populates="owner",
    collection_class=set,
    info={
        "doc": "Owned items",
        "direction": "OneToMany",
        "use_rel": True,
    },
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exdrf_al-0.1.8.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exdrf_al-0.1.8-py3-none-any.whl (61.0 kB view details)

Uploaded Python 3

File details

Details for the file exdrf_al-0.1.8.tar.gz.

File metadata

  • Download URL: exdrf_al-0.1.8.tar.gz
  • Upload date:
  • Size: 51.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for exdrf_al-0.1.8.tar.gz
Algorithm Hash digest
SHA256 168882a3a77c9c6b39b94d92f0200030a007b9c7d75ee30a59000921cef1572c
MD5 1b76034f8a3ba02fa45ddf4028717e85
BLAKE2b-256 82ca9e91b870b6bc1e3237f19814c93f5a9f9d9e159dfed9ac6d7614b18c0684

See more details on using hashes here.

File details

Details for the file exdrf_al-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: exdrf_al-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 61.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for exdrf_al-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fe3302318af3d6d58a7551bc956d1b927b8cf68eb8e027588df5cf7c59dd3821
MD5 66cbc1da0f7d12d29fcdb48e610e3234
BLAKE2b-256 f4be23548dbd1c58552a06b0063a89cb2219078decab924a0ecca5f692402c32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page