# Firestore Model

Este módulo permite manejar distintos métodos de Cloud Firestore (opens new window) para la gestión de dicha Base de Datos.

Si va a utilizar Firebase Model en un servidor personalizado, ó en modo local, recuerde utilizar una cuenta de servicio (opens new window)

# Funciones disponibles

# Query

La clase Query, implementada en el BackEndBase contiene las siguientes funciones:

  • and_
  • or_
  • get

# and_

@staticmethod
def and_(self, query_params, to_json=True, limit=None, select_fields=None, order_by=None):
    ...

# or_

@staticmethod
def or_(self, query_params=None, to_json=True):
    ...

# get

def get(self):
    ...

# FirestoreModel

La clase FirestoreModel, implementada en el BackEndBase contiene las siguientes funciones:

  • get_all_properties
  • get_prefix
  • dict_to_obj
  • to_json
  • save
  • save_and_set
  • multi_save
  • get_subcollection_by_id
  • subcollection
  • update_subcol
  • batch_counter
  • get_all
  • get_all_subcollections
  • get_all_collections
  • get_by
  • get_by_id
  • get_ref
  • get_custom_ref*
  • get_radius
  • geo_point
  • from_geo_point
  • raw_query
  • or_
  • and_
  • get
  • update
  • delete
  • deleteFields
  • delete_collection

# get_all_properties

@classmethod
def get_all_properties(self):
    ...

# get_prefix

@classmethod
def get_prefix(cls, collection_name):
    ...

# dict_to_obj

@classmethod
def dict_to_obj(cls, _dict=None, _name='from_dict'):
    ...

# to_json

@staticmethod
def to_json(docs, key=False):
    ...

# save

@classmethod
def save(self, data=None):
    ...

# save_and_set

@classmethod
def save_and_set(self, key, data=None):
    ...

# multi_save

@classmethod
def multi_save(self, data=None, is_dict=False):
    ...

# get_subcollection_by_id

@classmethod
def get_subcollection_by_id(self, key, sub_col='versions', sub_col_id=1, as_object=False):
    ...

# subcollection

@classmethod
def subcollection(self, id, data=None, sub_col='versions', sub_col_id=1, sub_col_data=None):
    ...

# update_subcol

@classmethod
def update_subcol(self, id, sub_col='versions', sub_col_id=1, sub_col_data=None):
    ...

# batch_counter

@classmethod
def batch_counter(self, data=None, update_mode='increment', stats_ref='--stats--'):
    ...

# get_all

@classmethod
def get_all(self, limit=None, select_fields=None):
    ...

# get_all_subcollections

@classmethod
def get_all_subcollections(self, id, sub_col=None, limit=None, select_fields=None):
    ...

# get_all_collections

@classmethod
def get_all_collections(self):
    ...

# get_by

@classmethod
def get_by(self, key, value, limit=None, select_fields=None):
    ...

# get_by_id

@classmethod
def get_by_id(self, key, as_object=False, select_fields=None):
    ...

# get_ref

@classmethod
def get_ref(self):
    ...

# get_ref

@classmethod
def get_custom_ref(collection_name):
    ...

# get_radius

@classmethod
def get_radius(self, coord=None, radio=10):
    ...

# geo_point

@classmethod
def geo_point(self, lat=None, lon=None):
    ...

# from_geo_point

@classmethod
def from_geo_point(self, coords=None):
    ...

# raw_query

@classmethod
def raw_query(self, params=None, to_json=True, limit=None, select_fields=None):
    ...

# or_

@classmethod
def or_(cls, q=(), to_json=True):
    ...

# and_

@classmethod
def and_(cls, q=(), to_json=True, limit=None, select_fields=None, order_by=None):
    ...

# get

@classmethod
def get(cls, doc_id, raise_exception=False):
    ...

# update

@classmethod
def update(self, key=None, data=None):
    ...

# delete

@classmethod
def delete(self, key=None):
    ...

# deleteFields

@classmethod
def deleteFields(self, key=None, select_fields=None):
    ...

# delete_collection

@classmethod
def delete_collection(self):
    ...

# Un ejemplo











 








from app.companies.models.Companies import Companies
...

try:
    _new_company = Companies()

    _new_company.name = name
    _new_company.address = address
    _new_company.email = email
    
    result = Companies.save(_new_company)

    if result is not None:
        print('Company created successfully ID:', result.id)
    else:
        print(str(result))
except Exception as e:
    print("Save Companies Exception:", e)

El resultado del ejemplo anterior, en caso de que todo esté bien:

>>> Company created successfully ID: FHQK9GVak5aKnY8kvCCY

Los resultados varían en caso de que ocurra algún error.

{
  "data": null,
  "message": "missing fields: ['name', 'address', 'email']",
  "status": 400
}

etc...

# Más información

Para mas información consulte: