Firebase-ORM is a tiny wrapper on top of firebase-admin that makes life easier when dealing with Firestore collections. Firebase-ORM tries to ease the development of apps that rely on Firestore at the database layer by abstracting the access layer providing a familiar repository pattern. It basically helps us not worry about Firestore details and focus on what matters: adding cool new features!
⚠️ This is a maintained fork of the original Firebase-ORM project. New features and bug fixes will be added here.
- Install the npm package:
yarn add firebase-orm reflect-metadata #or npm install firebase-orm reflect-metadata
# note: the reflect-metadata shim is required- Initialize your Firestore application:
import * as admin from 'firebase-admin';
import * as firebaseOrm from 'firebase-orm';
const serviceAccount = require('../firestore.creds.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`,
});
const firestore = admin.firestore();
firebaseOrm.initialize(firestore);- Create your Firestore models:
import { Collection } from 'firebase-orm';
@Collection()
class Todo {
id: string;
text: string;
done: Boolean;
}- Do cool stuff with firebase-orm!
import { Collection, getRepository } from 'firebase-orm';
@Collection()
class Todo {
id: string;
text: string;
done: Boolean;
}
const todoRepository = getRepository(Todo);
const todo = new Todo();
todo.text = "Check firebase-orm's Github Repository";
todo.done = false;
const todoDocument = await todoRepository.create(todo); // Create todo
const mySuperTodoDocument = await todoRepository.findById(todoDocument.id); // Read todo
await todoRepository.update(mySuperTodoDocument); // Update todo
await todoRepository.delete(mySuperTodoDocument.id); // Delete todoFirestore has support for complex data types such as GeoPoint and Reference. Full handling of complex data types is being handled in this issue. Temporarily, firebase-orm will export Class Transformer's @Type decorator. It receives a lamda where you return the type you want to cast to. See GeoPoint Example.
If you want to cast GeoPoints to your custom class, it must have latitude: number and longitude: number as public class fields. Hopefully this won't be a limitation in v1.
- Clone the project from github:
git clone [email protected]:deyvi-dev/firebase-orm.git- Install the dependencies:
yarn # npm installFirebase-orm has two types of tests:
- Unit tests:
yarn test # or npm test - Integration tests:
yarn test:integration # or npm test:integration
To be able to run the integration tests you need to create a Firebase service account and declare some environment variables.
Test files must follow the naming convention *.test.ts and use jest as the test runner.
This repo uses Conventional Commits as the commit messages convention.
This repo uses Semantic Release to automatically release new versions as soon as they land on master.
Commits must follow Angular's Git Commit Guidelines.
Supported commit types (taken from here):
- feat: A new feature
- fix: A bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- refactor: A code change that neither fixes a bug nor adds a feature
- perf: A code change that improves performance
- test: Adding missing or correcting existing tests
- chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
Manual Release
If, by any reason, a manual release must be done, these are the instructions:- To release a new version to npm, first we have to create a new tag:
npm version [ major | minor | patch ] -m "Relasing version"
git push --follow-tags- Then we can publish the package to npm registry:
npm publish- To deploy the documentation:
yarn deploy:doc # or npm deploy:doc- Firebase-orm uses typedoc to automatically build the API documentation, to generate it:
yarn build:doc # or npm build:docDocumentation is automatically deployed on each commit to master and is hosted in Github Pages in this link.
MIT © Willy Ovalle. See LICENSE for details.