Skip to main content

Quick mixin to provide basic features to firedantic

Project description

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.

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

firedantic_mixin-1.0.7.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

firedantic_mixin-1.0.7-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file firedantic_mixin-1.0.7.tar.gz.

File metadata

  • Download URL: firedantic_mixin-1.0.7.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1012-azure

File hashes

Hashes for firedantic_mixin-1.0.7.tar.gz
Algorithm Hash digest
SHA256 a413d482405c8b1d7bd4e66d938c3939de77993cd4e1bfef63ad15fdc1ca68df
MD5 8f56b1a126149e560cc66c6ff778fbdf
BLAKE2b-256 48cfa738b2a3b4f17802f42d37c1a56094322ff716ccc49a17389a3b821ed5e3

See more details on using hashes here.

File details

Details for the file firedantic_mixin-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: firedantic_mixin-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.0 Linux/6.2.0-1012-azure

File hashes

Hashes for firedantic_mixin-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6964b13a1e4c50d4b6df7a3c2514f8b053e6eab1d5b805e05bdd1b7d710c5000
MD5 673189dbb0d02ac32f7907bf49fee8c0
BLAKE2b-256 de968d0453d1042eaab63247a9632d43d7c892bf7b1bfb0f8d93dd0cc152b7d2

See more details on using hashes here.

Supported by

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