Skip to main content

用于 Google Firestore 数据库的离线可用的类似 ORM 的包装器

项目描述

火库

详情

Firestore 是 Google Firestore 上的离线可用 ORM/ODM。

存储库

https://github.com/workenvoy/firestore

作者

Workenvoy 公司 ( http://github.com/workenvoy )

维护者

雷蒙德·奥尔塞加 ( http://github.com/rayattack )

https://travis-ci.org/workenvoy/firestore.svg?branch=master https://coveralls.io/repos/github/workenvoy/firestore/badge.svg?branch=master

细节

Firestore 是一个 Python 对象文档/对象集合映射器,用于与 Google Firestore 一起使用。Google 提供的灵活、可扩展的实时数据库。您可以在https://firestore.readthedocs.io找到一些文档- 还有一个快速入门教程

离线支持

Firestore 目前使用内存中的数据存储来模拟离线工作时对 Google Firestore 的访问。磁盘有一个乐观的持久性,内容可以在 /projectdir/localfire 目录中看到。直接删除它意味着您丢失了在从磁盘中删除目录之前可能保存的所有数据。如果您想保留数据的副本,请务必制作此目录的副本,并鼓励您贡献,即打开问题,如果您想提供帮助,请提交拉取请求。

安装

我们推荐使用虚拟环境,例如virtualenv来控制你的包管理。Firestore 的安装很容易完成pip install -U firestore并且需要 pip。要安装。否则,您可以从GitHub下载源代码并运行python setup.py install

依赖项

我们试图将依赖项保持在最低限度,并且所有依赖项都可以使用pip获得。下面突出显示了使用 Firestore 所需的唯一依赖项:

  • 谷歌云火库

如果您正在处理广泛的日期,我们建议您使用日期解析器:

  • 日期实用程序>=2.1.0

例子

示例 Firestore 代码片段:

from firestore import Collection, Document, Reference as Ref
from firestore import Array
from firestore import Integer
from firestore import String
from firestore.lazy import Datatype

class SomeRootCollection(Collection):
    """
    Root collections inherit directly from collection, whilst
    sub collections will inherit from a document.

    To understand this always remember in Firestore a collection can never be
    a child of another collection, and a sub-collection will always live
    under a document.
    To have mongo style sub-collections use the Map datatype
    """
    pass


class User(SomeRootCollection):
    """
    This is the User document and will be saved under the
    collection `SomeRootCollection`.
    Documents live under collections or sub-collections directly
    """
    __private__ = ["password"]

    first_name = String(required=True)
    middle_name = Datatype(datatype="String")  # You can use Datatype in place of more specific types
    last_name = Datatype("StrInG")  # Case insensitive
    age = Integer(minimum=0)
    photos = Reference('Photo')
    password = String(minimum=6)  # private fields can not be viewed with get_XXX methods


class Photo(User):
    """
    This creates a photos subcollection under the User document for documents
    under the root collection
    """
    id = String(required=True, id=True)  # omit to have id auto-generated by cloud firestore
    photo_urls = Array()


# Create a text-based post
>>> user = User()
>>> user.first_name = "Alan"
>>> user.last_name = "Turing"
>>> user.photos.append("https://cloudinary.com/img.jpg")
>>>
>>> # this will persist user and photo at
>>> # once unlike user.save that will save only user
>>> user.persist()

# Sometimes you want one thing to succeed before doing another
>>> user.photos.safe_save()  # only saves if parent was prior saved else fails
>>> user.photos.save()  # saves regardless

# You can also save a photo by itself and query easily
>>> photo = Photo()
>>> photo.parent = user
>>> photo.save()  # save only photo
>>> photo.parent.save()

贡献

我们喜欢贡献者:贡献指南

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

firestore-0.0.8.tar.gz (25.5 kB 查看哈希

已上传 source

内置发行版

firestore-0.0.8-py3.7.egg (93.1 kB 查看哈希

已上传 3 7

firestore-0.0.8-py3-none-any.whl (40.0 kB 查看哈希

已上传 py3