galaxies-access-layer v1.1.0
GalaxiesAccessLayer
GalaxiesAccessLayer is a class designed to simplify interactions with Firebase Firestore. It provides methods for basic CRUD (Create, Read, Update, Delete) operations and advanced queries, making it easy to manage Firestore data.
Installation
To use GalaxiesAccessLayer, you first need to install it via npm or yarn. If it's available on npm, you can install it using the following commands:
Using npm:
npm install galaxies-access-layerOr using yarn:
yarn add galaxies-access-layerUsage
Import and Initialize
Import the
GalaxiesAccessLayerclass and initialize it with your Firebase configuration.import { GalaxiesAccessLayer } from "galaxies-access-layer"; const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_AUTH_DOMAIN", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID", measurementId: "YOUR_MEASUREMENT_ID", }; const accessLayer = new GalaxiesAccessLayer().setConfig(firebaseConfig);Add Data
Use the
addmethod to add a new document to a collection.const { id } = await accessLayer.add("user", { firstname: "john", lastname: "doe", }); console.log("Added User ID:", id);Get Data
Retrieve a document by its ID using the
getmethod.const user = await accessLayer.get("user", id); console.log("User Data:", user);Update Data
Update an existing document with the
updatemethod.const updatedUser = await accessLayer.update("user", id, { firstname: "mark", }); console.log("Updated User:", updatedUser);Delete Data
Delete a document using the
deletemethod.const deletedUser = await accessLayer.delete("user", id); console.log("Deleted User ID:", deletedUser.id);Fetch Data
Fetch all documents from a collection with the
fetchmethod.await Promise.all([ accessLayer.add("user", { firstname: "john", lastname: "doe", }), accessLayer.add("user", { firstname: "mark", lastname: "den", }), ]); const fetchedUsers = await accessLayer.fetch("user"); console.log("Fetched Users:", fetchedUsers);Query Data
Perform a basic query using the
querymethod.const queryUser = await accessLayer.query("user", "firstname", "==", "john"); console.log("Queried Users:", queryUser);Advanced Query
Execute more complex queries with the
advancedQuerymethod.const advanceQueryUser = await accessLayer.advancedQuery("user", [ { field: "firstname", operator: "!=", value: "john" }, ]); console.log("Advanced Queried Users:", advanceQueryUser);
Configuration
When initializing GalaxiesAccessLayer, provide the following Firebase configuration options:
apiKey: Your Firebase API key.authDomain: Firebase Auth domain.projectId: Firebase project ID.storageBucket: Firebase storage bucket.messagingSenderId: Firebase messaging sender ID.appId: Firebase app ID.measurementId: Firebase measurement ID (optional).