0.0.5 • Published 1 year ago

blazeorm v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

BlazeORM 🔥

A simple typed orm for firebase firestore using zod

import { blazeTable } from "blazeorm";
import { z } from "zod";
export const users = blazeTable(
	"users",
	z.object({
		name: z.string(),
		email: z.string().email(),
		profile: z.string().url().optional(),
		role: z.enum(["admin", "manager"]),
	})
);

Features 🚀

  • Typed insert, update functions.
  • Typed colleciton and document ref
  • Typed getters
  • Input validation using zod during insertion / update

Docs:

Installation

npm install blazeorm
yarn add blazeorm
pnpm add blazeorm

API

Create a model

import { blazeTable } from "blazeorm";
import { z } from "zod";
export const users = blazeTable(
	"users",
	z.object({
		name: z.string(),
		email: z.string().email(),
		role: z.enum(["admin", "manager"]),
	})
);

Create new document

It will do runtime validation before creating. Will throw ZodError instance if failed

users.create({
	name: "Test Name",
	email: "johndoe@gmail.com",
	role: "Admin", // type error
});

Update document

Update with partial data. It will merge with preexisting data. It will also do runtime validation before updating. Will throw ZodError instance if failed.

users.update("testId", {
	name: "Test Name",
	role: "Admin", // type error
});

Collection reference

const colRef = users.collection;

Document Reference

const docRef = users.doc("testId");

Get document by id

const data = await users.findById("testId");

Complex queries

Run any query you want with firestore query builder. Use the keys from the model for type safety

import { query, where } from "firebase/firestore";
import { users } from "./model";
const usersColRef = users.collection;
const snapshop = await query(usersColRef, where(users.role, "==", "manager"));
const data = snapshot.data(); //typed from the user model
0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago