Firedantic Order by / Select / Limit
Objective
This is a quick 'monkeypatch' / mixin for Firedantic to provide missing capabilities Based on the issue https://github.com/ioxiocom/firedantic/issues/43
Firedantic is a pydantic wrapper for Google Firestore, it's actually quite handy, however it is missing some design / direction and strategy.
Currently is no select, order_by capabilities, which limits (a function also missing) you to filter and listing, reducing the ability to use it for most needs.
Attempts to influence and encourage direction are met with hostility from the maintainer(s). This had driven the direction of this solution to use a monkey patch and extension to allow for easy integration.
Installation
Standard install, note - vs _
poetry add firedantic-mixin
Usage
from firedantic_mixin.mixin import FiredanticMonkey
How to use
Simply swap the super class of firedantic.Model for FiredanticMonkey
| Firedantic standard | Firedantic mixin |
|---|---|
from firedantic import Model
class Orders(Model):
__collection__ = "Monkey-Orders"
item : str
quantity : int
price: float
|
from firedantic_mixin.mixin import FiredanticMonkey
class Orders(FiredanticMonkey):
__collection__ = "Monkey-Orders"
item : str
quantity : int
price: float
|
This opens up the ability to do standard compound tasks by returning Firestores BaseQuery
# return just item and price fields, order by price
query = Orders.select(['item', 'price']).\
order_by("price", Query.ASCENDING)
results = list(query.stream())
Results will be Firestores DocumentSnapshots to go back to a Firedantic model simply do:
models = Orders.to_dantic(results)
What else can you now do?
As you have direct access to BasicQuery as part of the model
Orders.query() # returns a BaseQuery
Orders.query({"price": {">": 1}}) # filtering
Orders.query().offset(20).limit(10) # pagination
Orders.select(['item', 'price']) # field selects
Orders.query().order_by("price", Query.ASCENDING) # ordering by
There is currently less than 70 lines of code that just opens this up and makes it usable.
Metadata
Release files for firedantic-mixin 1.0.8
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 | Actions |
|---|---|---|---|---|
| firedantic_mixin-1.0.8.tar.gz | 7.7 kB | Without provenance | Details for firedantic_mixin-1.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| firedantic_mixin-1.0.8-py3-none-any.whl | Python 3 | none | any | Details for firedantic_mixin-1.0.8-py3-none-any.whl |
Total release size: 16.2 kB
Release files / firedantic_mixin-1.0.8.tar.gz
| Download URL | firedantic_mixin-1.0.8.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b56f34223b5a7a7d578dc30659e07bb274e928affd74e6150c776bfaff8970dc
|
|
BLAKE2b-256 checksum How to use checksums |
1fd7c55fcc3b2a9ea20f94ffd840d133d021de8db2f38ffb6eb9f99580d331dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1012-azure
|
Release files / firedantic_mixin-1.0.8-py3-none-any.whl
| Download URL | firedantic_mixin-1.0.8-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e476145b033937d888a6a2e0349833938666c8287e76a22387b05fe4ca72a86
|
|
BLAKE2b-256 checksum How to use checksums |
22cd660565bd71a1dbb18fab9730e7bddcb8d21770e451e4b5b30c0c887c40ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1012-azure
|
Security for firedantic-mixin 1.0.8
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.