npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firestore_goose

v0.0.9

Published

ORM library for firestore based on mongoose

Downloads

15

Readme

firestore_goose

The firestore_goose is library for working with firestore. it makes it easy to work with firestore. it built on top of firsbase-admin. You still need to understand the basics of firestore to use this library it main purpose is to make it easy using firestore

Prerequisite

  • make sure you have firebase-admin installed
npm i firebase-admin
  • make sure you have initialized your firebase project
const firebaseAdmin = require("firebase-admin");
firebaseAdmin.initializeApp();

Installation

Using npm

npm i firestore_goose

Node.js

const FirestoreGoose = require("firestore_goose");

Basic Usage

const fireSG = new FirestoreGoose(firebaseAdmin);

firebaseAdmin : The initialize firebase admin instance

Example 1 - Adding data

let userCollection = "user";
let userID = "John";
let userDetails = {
  lastName: "Doe",
  age: 20,
  kidsNames: ["Jam", "Mike"],
  weeklyCars: { monday: "ferrari", tuesday: "benz" },
};

let query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  value: userDetails, // firestore fieldValue
};
fireSG.add(query).then((response) => {
  console.log(response);
});
// save another data
let query2 = { path: userCollection, key: "Jane", value: "Doe" };
fireSG.add(query2).then((response) => {
  console.log(response);
});

/*
--response--
{
  id: '5t7AyoVQOgOhXap63wtW',
  data: {
    John: {
      kidsNames: [Array],
      lastName: 'Doe',
      weeklyCars: [Object],
      age: '20'
    },
  }
}
*/

NOTE

To overwrite a field you use fireSG.add(query,{force:true}) This will overwrite the existing field data

  • id : The document id
  • data : The document data

Example 2 - Adding data using transaction

let detailsToUpdate = "random data";
query = {
  path: userCollection, //firestore collection
  value: detailsToUpdate // firestore nested field value
};
fireSG.addWithTransaction(query);
/*
it stores items in an array using firebase transaction
*/
  • value : The data we want to add to transaction array

Example 3 - Updating data

Note: Only existing document can be updated

let detailsToUpdate = "age";
let updatedAge = 35;
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  childObject: detailsToUpdate, // firestore nested field Key
  value: updatedAge, // firestore nested field value
};
fireSG.updateByID(query);
/*
--response--
John.age updated successfully

--output--
John.age = 35
*/
  • childObject : The nested field object key we want to update

Example 4 - Update : add to nested object

detailsToUpdate = "weeklyCars.wednesday";
let updatedCar = "bmw";
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  childObject: detailsToUpdate, // firestore nested field Key
  value: updatedCar, // firestore nested field value
};
fireSG.updateByID(query);
/*
--response--
John.weeklyCars.wednesday updated successfully
--output--
John.weeklyCars = { monday: 'ferrari', tuesday: 'benz', wednesday: 'bmw' }
*/

Example 5 - Update : add new value to array

detailsToUpdate = "kidsNames";
let childToAdd = "Jerry";
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  childArrayAdd: detailsToUpdate, // firestore nested field array Key
  value: childToAdd, // firestore nested field array value
};
fireSG.updateByID(query);
/*
--response--
John.kidsNames updated successfully

--output--
John.kidsNames = ['Jam', 'Mike', 'Jerry']
*/

Example 6 - Update : remove value from array

detailsToUpdate = "kidsNames";
let childToRemove = "Mike";
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  childArrayRemove: detailsToUpdate, // firestore nested field array Key
  value: childToRemove, // firestore nested field array value
};
fireSG.updateByID(query);
/*
--response--
John.kidsNames updated successfully

--output--
John.kidsNames = ['Jam', 'Jerry']
*/

Example 7 - Get : field by id

query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
};
fireSG.getByID(query);
/*
--response--
{
  lastName: 'Doe',
  weeklyCars: { tuesday: 'benz', monday: 'ferrari' },
  age: 35,
  kidsNames: [ 'Jam', 'Jerry' ]
}
*/
  • response : it returns only one field data

Example 8 - Get : all field in a collection

query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
};
fireSG.getByID(query);
/*
--response--
{
  lastName: 'Doe',
  weeklyCars: { tuesday: 'benz', monday: 'ferrari' },
  age: 35,
  kidsNames: [ 'Jam', 'Jerry' ]
}
*/
  • response : it returns only one field data

Example 9 Find- value in transaction

query = {
  path: userCollection, //firestore collection
  value: detailsToFind // string ::
};
fireSG.findValueInTransaction(query);
/*
--response--
{
  true
}
*/

Example 10 - Get : all value in transaction

query = {
  path: userCollection, //firestore collection
};
fireSG.getAllFromTransaction(query);
/*
--response--
{
  
  John.txId: [...],
}
*/

Example 10 - Get : last document in the collection

query = {
  path: userCollection, //firestore collection
};
fireSG.getLast(query);
/*
--response--
{
  
  John: {...},
  Jane: ...
}
*/

Example 11 - Delete : field by id

userID = "Jane";
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
};
fireSG.delete(query);
/*
--response--
Jane deleted successfully
*/

Example 12 - Delete : a value in a nested field

userID = "John";
detailsToUpdate = "weeklyCars.tuesday";
query = {
  path: userCollection, //firestore collection
  key: userID, // firestore fieldKey
  childObject: detailsToUpdate, // firestore nested field Key
};
fireSG.delete(query);
/*
--response--
John.weeklyCars.tuesday deleted successfully
--output--
John.weekly = { monday: 'ferrari' }
*/