super-firebase-hooks
v1.3.3
Published
Its simple firebase query , that inspired by sql like syntax, easy to remember and use
Downloads
16
Maintainers
Readme
# super-firebase-hook
`super-firebase-hook` is a simple wrapper around Firebase Firestore SDK version 9 that provides a chainable API for performing CRUD operations.
Installation
- Install Firebase SDK version 9 in your project:
npm install firebase super-firebase-hooks
- Create a new file named
firebase.js
and import theFirebaseQuery
wrapper. Initialize it with your Firebase configuration and export it:
import { initializeApp } from "firebase/app";
import { getFirestore, collection, query, where, getDocs, addDoc, doc, updateDoc, deleteDoc } from "firebase/firestore";
import FirebaseQuery from 'super-firebase-hooks';
const firebaseConfig = {
// your Firebase config here
};
const firebaseApp = initializeApp(firebaseConfig);
const DB = getFirestore(firebaseApp);
const firebase = new FirebaseQuery(DB);
export default firebase;
Usage
Import the firebase
wrapper in your file and use it to perform CRUD operations:
Select documents
Select all documents from the users
collection:
import firebase from "./firebase";
const { data, error } = await firebase.select("users").get();
console.log(data);
Select documents by ID
Select all documents from the users
collection:
import firebase from "./firebase";
const { data, error } = await firebase.select("users").getById("userid");
console.log(data);
Query documents
Query documents from the users
collection where the age
field is greater than or equal to 18:
import firebase from "./firebase";
const { data, error } = await firebase
.select("users")
.where("age", ">=", 18)
.get();
console.log(data);
Insert a document
Insert a new document into the users
collection:
import firebase from "./firebase";
const { error } = await firebase.select("users").insert({ name: "Ahmad" });
console.log(error);
Insert a new document into the users
collection with id:
import firebase from "./firebase";
const { error } = await firebase
.select("users")
.insert({ name: "Ahmad" }, "docId");
console.log(error);
Insert many document
Insert a new document into the users
collection:
import firebase from "./firebase";
const { ids, error } = await firebase
.select("users")
.insertMany([{ name: "Ahmad" }, { name: "Ali" }]);
console.log(error);
Update a document
Update a document in the users
collection by its document ID:
import firebase from "./firebase";
const { error } = await firebase
.select("users")
.update("docId", { name: "John" });
console.log(error);
Delete a document
Delete a document in the users
collection by its document ID:
import firebase from "./firebase";
const { error } = await firebase.select("users").delete("docId");
console.log(error);
License
super-firebase-hooks
is released under the MIT License.
Github Repo for open source contribute
https://github.com/m-ahmad001/super-firebase-hooks