firedantic-mixin


Namefiredantic-mixin JSON
Version 1.0.8 PyPI version JSON
download
home_page
SummaryQuick mixin to provide basic features to firedantic
upload_time2023-10-07 22:23:58
maintainer
docs_urlNone
authorpatrick o'leary
requires_python>=3.11,<4.0
licenseCC-BY-4.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## 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
```python
from firedantic_mixin.mixin import FiredanticMonkey
```

### How to use

Simply swap the super class of firedantic.Model for FiredanticMonkey

<table>
<tr><th>Firedantic standard</th><th> Firedantic mixin</th></tr>
<tr><td>

 ```python
 from firedantic import Model

 class Orders(Model):  
    __collection__ = "Monkey-Orders"
    
    item : str
    quantity : int
    price: float

```

</td><td>

```python
from firedantic_mixin.mixin import FiredanticMonkey

class Orders(FiredanticMonkey): 
    
    __collection__ = "Monkey-Orders"
    
    item : str
    quantity : int
    price: float

```
</td></tr>
</table>

This opens up the ability to do standard compound tasks by returning [Firestores BaseQuery](https://cloud.google.com/python/docs/reference/firestore/latest/google.cloud.firestore_v1.base_query.BaseQuery)

```python

# 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](https://cloud.google.com/python/docs/reference/firestore/latest/google.cloud.firestore_v1.base_document.DocumentSnapshot) to go back to a Firedantic model simply do: 

```python

models = Orders.to_dantic(results)

```

### What else can you now do? 

As you have direct access to BasicQuery as part of the model


```python

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.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "firedantic-mixin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "patrick o'leary",
    "author_email": "pjaol@pjaol.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/d7/c55fcc3b2a9ea20f94ffd840d133d021de8db2f38ffb6eb9f99580d331dd/firedantic_mixin-1.0.8.tar.gz",
    "platform": null,
    "description": "## Firedantic Order by / Select  / Limit\n\n\n### Objective \nThis is a quick 'monkeypatch' / mixin for Firedantic to provide missing capabilities\nBased on the issue https://github.com/ioxiocom/firedantic/issues/43\n\nFiredantic is a pydantic wrapper for Google Firestore, it's actually quite handy, however it is missing some design / direction and strategy. \n\nCurrently 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. \n\nAttempts to influence and encourage direction are met with hostility from the maintainer(s).\nThis had driven the direction of this solution to use a monkey patch and extension to allow for easy integration. \n\n### Installation \n\nStandard install, note - vs _\n\n```\npoetry add firedantic-mixin\n```\n\nUsage\n```python\nfrom firedantic_mixin.mixin import FiredanticMonkey\n```\n\n### How to use\n\nSimply swap the super class of firedantic.Model for FiredanticMonkey\n\n<table>\n<tr><th>Firedantic standard</th><th> Firedantic mixin</th></tr>\n<tr><td>\n\n ```python\n from firedantic import Model\n\n class Orders(Model):  \n    __collection__ = \"Monkey-Orders\"\n    \n    item : str\n    quantity : int\n    price: float\n\n```\n\n</td><td>\n\n```python\nfrom firedantic_mixin.mixin import FiredanticMonkey\n\nclass Orders(FiredanticMonkey): \n    \n    __collection__ = \"Monkey-Orders\"\n    \n    item : str\n    quantity : int\n    price: float\n\n```\n</td></tr>\n</table>\n\nThis opens up the ability to do standard compound tasks by returning [Firestores BaseQuery](https://cloud.google.com/python/docs/reference/firestore/latest/google.cloud.firestore_v1.base_query.BaseQuery)\n\n```python\n\n# return just item and price fields, order by price\nquery = Orders.select(['item', 'price']).\\\n            order_by(\"price\", Query.ASCENDING)\n\nresults = list(query.stream())\n\n```\n\nResults will be [Firestores DocumentSnapshots](https://cloud.google.com/python/docs/reference/firestore/latest/google.cloud.firestore_v1.base_document.DocumentSnapshot) to go back to a Firedantic model simply do: \n\n```python\n\nmodels = Orders.to_dantic(results)\n\n```\n\n### What else can you now do? \n\nAs you have direct access to BasicQuery as part of the model\n\n\n```python\n\nOrders.query() # returns a BaseQuery\nOrders.query({\"price\": {\">\": 1}}) # filtering\n\nOrders.query().offset(20).limit(10) # pagination\n\nOrders.select(['item', 'price']) # field selects\n\nOrders.query().order_by(\"price\", Query.ASCENDING) # ordering by \n\n```\n\nThere is currently less than 70 lines of code that just opens this up and makes it usable.\n",
    "bugtrack_url": null,
    "license": "CC-BY-4.0",
    "summary": "Quick mixin to provide basic features to firedantic",
    "version": "1.0.8",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22cd660565bd71a1dbb18fab9730e7bddcb8d21770e451e4b5b30c0c887c40ce",
                "md5": "8d452c7286e6646062ca6a6ff6a59630",
                "sha256": "1e476145b033937d888a6a2e0349833938666c8287e76a22387b05fe4ca72a86"
            },
            "downloads": -1,
            "filename": "firedantic_mixin-1.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d452c7286e6646062ca6a6ff6a59630",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 8504,
            "upload_time": "2023-10-07T22:23:57",
            "upload_time_iso_8601": "2023-10-07T22:23:57.301462Z",
            "url": "https://files.pythonhosted.org/packages/22/cd/660565bd71a1dbb18fab9730e7bddcb8d21770e451e4b5b30c0c887c40ce/firedantic_mixin-1.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1fd7c55fcc3b2a9ea20f94ffd840d133d021de8db2f38ffb6eb9f99580d331dd",
                "md5": "09b35b83923f9aea4e85f246c7517f6a",
                "sha256": "b56f34223b5a7a7d578dc30659e07bb274e928affd74e6150c776bfaff8970dc"
            },
            "downloads": -1,
            "filename": "firedantic_mixin-1.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "09b35b83923f9aea4e85f246c7517f6a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11,<4.0",
            "size": 7727,
            "upload_time": "2023-10-07T22:23:58",
            "upload_time_iso_8601": "2023-10-07T22:23:58.868406Z",
            "url": "https://files.pythonhosted.org/packages/1f/d7/c55fcc3b2a9ea20f94ffd840d133d021de8db2f38ffb6eb9f99580d331dd/firedantic_mixin-1.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-07 22:23:58",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "firedantic-mixin"
}
        
Elapsed time: 0.12210s