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-db-orm

v1.5.1

Published

ORM for the database in Firestore

Downloads

32

Readme

Firestore DB ORM

firestore-db-orm is a simple ORM library for Firestore, designed to provide easy-to-use, TypeScript-typed CRUD operations.

Installation

Install firebase-db-orm with bun

bun add firestore-db-orm

Instantiate the ORM

import { FirestoreORM } from "firestore-db-orm";
import { db } from "./firestore";
import type { IUser } from "./user.interface";

const userORM = new FirestoreORM<IUser>(db, "users");
export default userORM;

Complete Example

import userORM from "./user.orm";
import { v4 } from "uuid";

(async () => {
  const newUser = await userORM.add({
    id: v4(),
    email: "[email protected]",
    password: "securepassword",
  });
  console.log("New user created:", newUser);

  const user = await userORM.get(newUser.id);
  if (user) {
    console.log("User found:", user);
  }

  await userORM.update(newUser.id, { email: "[email protected]" });
  await userORM.delete(newUser.id);

  const otherUser = await userORM.findOne({
    email: { where: "==", value: "[email protected]" },
  });
})();

Examples of finds Method

Example 1: Simple Search

Find documents where age is equal to 25.

const searchParams1: SearchParams = {
  age: 25,
};

const result1 = await userORM.finds(searchParams1);
console.log(result1);

Example 2: Search with Simple Condition

Find documents where age is greater than 18.

const searchParams2: SearchParams = {
  age: {
    value: 18,
    where: ">",
  },
};

const result2 = await userORM.finds(searchParams2);
console.log(result2);

Example 3: Search with Multiple Conditions for the Same Field

Find documents where age is greater than 10 and less than 30.

const searchParams3: SearchParams = {
  age: [
    {
      value: 10,
      where: ">",
    },
    {
      value: 30,
      where: "<",
    },
  ],
};

const result3 = await userORM.finds(searchParams3);
console.log(result3);

Example 4: Search with Multiple Fields and Conditions

Find documents where age is greater than 18 and name is equal to "Juan".

const searchParams4: SearchParams = {
  age: {
    value: 18,
    where: ">",
  },
  name: "Juan",
};

const result4 = await userORM.finds(searchParams4);
console.log(result4);

Example 5: Search with Multiple Fields and Multiple Conditions

Find documents where age is within certain ranges and name is equal to "Ana".

const searchParams5: SearchParams = {
  age: [
    {
      value: 10,
      where: ">",
    },
    {
      value: 30,
      where: "<",
    },
  ],
  name: "Ana",
};

const result5 = await userORM.finds(searchParams5);
console.log(result5);

Example 6: Complex Search with Several Fields and Conditions

Find documents where age is greater than 10 and less than 30, name is "Pedro", and active is true.

const searchParams6: SearchParams = {
  age: [
    {
      value: 10,
      where: ">",
    },
    {
      value: 30,
      where: "<",
    },
  ],
  name: "Pedro",
  active: true,
};

const result6 = await userORM.finds(searchParams6);
console.log(result6);

License

MPL-2.0