xp-repository
v0.0.6
Published
This package provides a convenient interface for interacting with Firestore databases in your Node.js applications.
Downloads
13
Readme
Firestore Database Interface
Introduction
This package provides a convenient interface for interacting with Firestore databases in your Node.js applications. It offers functions for common database operations such as inserting, updating, deleting, and querying documents.
Installation
You can install the package via npm or yarn:
npm install xp-repositoryor
yarn add xp-repositoryUsage
First, import the package in your application:
import makeRepository from "xp-repository";Then, create a database interface by passing a function to initialize Firestore:
import { Firestore } from "@google-cloud/firestore";
const firestore = new Firestore();
const repository = makeRepository(() => firestore);Now, you can use the database interface to perform various operations:
// Insert a new document
await db("users").insert({ name: "John Doe", age: 30 });
// Update an existing document
await db("users").update("userId", { age: 31 });
// Retrieve all documents
const allUsers = await db("users").findAll();
// Find documents by a key-value pair
const activeUsers = await db("users").findAllByKeyValue("status", "active");
// Find a document by ID
const user = await db("users").findById("userId");
// Remove a document by ID
await db("users").remove("userId");