firebase-ts-class
v1.0.3
Published
Modulo en forma de clases para firebase
Downloads
7
Readme
Modulo para usar las herramientas de Firebase
Importar el modulo
import {module} from 'firebase-ts-class';
Firestore
- Para usar el modulo de
Firestore
se debe crear el objetoFirestore
const config = {
projectId: '', // project id
keyFilename: '' // path service account
};
const Firestore = new module.Firestore(config);
Funciones
- Agregar nuevo documento
add(ref, data)
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';
data = {
llave: 'valor',
...
llaveN: 'valorN'
};
Firestore.add(ref, data);
await Firestore.add(ref, data);
- Actualizar documento
update(ref, data)
// En esta funcion siempre se debe hacer uso del idDocumento
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';
data = {
llave: 'valor',
...
llaveN: 'valorN'
};
Firestore.update(ref, data);
await Firestore.update(ref, data);
- Obtener uno o varios documentos
get(ref)
const ref = 'nombreColeccion/idDocumento/nombreColeccion_2/idDocumento_2...';
Firestore.get(ref);
await Firestore.get(ref);
- Obtener sub colecciones
getGroup(nombreColeccion)
const nombreColeccion = 'subColeccion';
Firestore.getGroup(nombreColeccion);
await Firestore.getGroup(nombreColeccion);
- Obtener sub colecciones con filtros
getGroupQuery(nombreColeccion, query)
const nombreColeccion = 'subColeccion';
const query = [
{
campo: 'nombreCampo',
valor: 'valor',
operador: '[operador]'
},
...
{
campo: 'nombreCampoN',
valor: 'valorN',
operador: '[operadorN]'
}
]
//operadores validos '==', '<=', '>=', '<', '>', 'array-contains'
Firestore.getGroupQuery(nombreColeccion, query);
await Firestore.getGroupQuery(nombreColeccion, query);
- Obtener documentos por query
getQuery(ref, query)
const ref = 'nombreColeccion/idDoc..../nombreColeccionN';
const query = [
{
campo: 'nombreCampo',
valor: 'valor',
operador: '[operador]'
},
...
{
campo: 'nombreCampoN',
valor: 'valorN',
operador: '[operadorN]'
}
]
//operadores validos '==', '<=', '>=', '<', '>', 'array-contains'
//La referencia solo debe llegar hasta el nombre de la coleccion
Firestore.getQuery(ref, query);
await Firestore.getQuery(ref, query);