Use SQLAlchemy with Ex-DRF.
Project description
SqlAlchemy support for Ex-DRF
exdrf-al is the SQLAlchemy 2.x bridge for exdrf: declarative
metadata is turned into ExDataset / ExResource / ExField trees used by
generators (al2pd, al2qt, al2r, …), Qt (exdrf-qt), and Alembic
helpers (Click commands in this package). It depends on exdrf and
exdrf-pd.
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 and 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 can 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 inexdrf. label_dsl; it is used to generate code that computes the label of a record given the record. Theexdrf.label_dslmodule 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
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 exdrf_al-0.1.16.tar.gz.
File metadata
- Download URL: exdrf_al-0.1.16.tar.gz
- Upload date:
- Size: 51.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a8de383af44592a570a5a94c76b65d707640e2c572abe59a969654bb0b0982
|
|
| MD5 |
2ae66829d1538c081d96a579fe2ec67a
|
|
| BLAKE2b-256 |
2a03aa99179a256b0a8694d1128cffb16bbd4e0298678bcd9bfcbcc88db0802c
|
File details
Details for the file exdrf_al-0.1.16-py3-none-any.whl.
File metadata
- Download URL: exdrf_al-0.1.16-py3-none-any.whl
- Upload date:
- Size: 61.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78a611af066eeace71a14b349d7c0956fb55b1c066ed44a6f3d25cbb45525172
|
|
| MD5 |
fd87d766a905ab7aafaa25b63c28b589
|
|
| BLAKE2b-256 |
b2e319e527d8eed84f5245f0e7257f32fbb514fb3cde97d0cb616c2caa2acf72
|