Giter Site home page Giter Site logo

gregfenton / fireorm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wovalle/fireorm

0.0 1.0 0.0 2.55 MB

ORM for firestore πŸ”₯

Home Page: https://fireorm.js.org

License: MIT License

TypeScript 95.97% HTML 1.83% JavaScript 2.08% Shell 0.12%

fireorm's Introduction

fireormπŸ”₯

NPM Version Build Status Typescript lang All Contributors License Gitter chat

Fireorm is a tiny wrapper on top of firebase-admin that makes life easier when dealing with a Firestore database. Fireorm tries to ease the development of apps that rely on Firestore at the database layer by abstracting the access layer providing and familiar repository pattern. It basically helps us not worrying about Firestore details and focusing in what matters: adding cool new features!

You can read more about the motivations and features of fireorm on its introductory post. Also, the API documentation is available.

Usage

  1. Install the npm package:
yarn add fireorm reflect-metadata #or npm install fireorm reflect-metadata

# note: reflect-metadata shim is required
  1. Initialize your firestore application:
import * as admin from 'firebase-admin';
import * as fireorm from 'fireorm';

const serviceAccount = require('../firestore.creds.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`,
});

const firestore = admin.firestore();
fireorm.initialize(firestore);
  1. Create your firestore models!
import { Collection } from 'fireorm';

@Collection()
class Todo {
  id: string;
  text: string;
  done: Boolean;
}
  1. Do cool stuff with fireorm!
import { Collection, getRepository } from 'fireorm';

@Collection()
class Todo {
  id: string;
  text: string;
  done: Boolean;
}

const todoRepository = getRepository(Todo);

const todo = new Todo();
todo.text = "Check fireorm'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 todo

Firebase Complex Data Types

Firestore has support for complex data types such as GeoPoint and Reference. Full handling of complex data types is being handled in this issue. Temporarily, Fireorm will export Class Transformer's @Type decorator. It receives a lamda where you have to return the type you want to cast to. See GeoPoint Example.

Limitations

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.

Development

Initial Setup

  1. Clone the project from github:
git clone [email protected]:wovalle/fireorm.git
  1. Install the dependencies.
yarn # npm install

Testing

Fireorm 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'll 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.

Committing

This repo uses Conventional Commits as the commit messages convention.

Release a new version

This repo uses Sematic 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

Documentation

  • Fireorm uses typedoc to automatically build the API documentation, to generate it:
yarn build:doc # or npm build:doc

Documentation is automatically deployed on each commit to master and is hosted in Github Pages in this link.

Contributing

Have a bug or a feature request? Please search the issues to prevent duplication. If you couldn't find what you were looking for, proceed to open a new one. Pull requests are welcome!

Contributors

Thanks goes to these wonderful people (emoji key):


Willy Ovalle

πŸ’» πŸ“– πŸ’‘ πŸ€” πŸ‘€ ⚠️

Maximo Dominguez

πŸ€” πŸ’»

Nathan Jones

πŸ’»

Sergii Kalashnyk

πŸ’»

SaltyKawaiiNeko

πŸ’» πŸ€”

z-hirschtritt

πŸ’» πŸ€”

Joe McKie

πŸ’» πŸ€”

Samed Düzçay

πŸ’»

stefdelec

πŸ’»

Łukasz Kuciel

πŸ’»

Yaroslav Nekryach

πŸ’»

Dmytro Nikitiuk

πŸ’»

JingWangTW

πŸ’»

Rink Stiekema

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT Β© Willy Ovalle. See LICENSE for details.

fireorm's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar jingwangtw avatar joemckie avatar jonesnc avatar kronhyx avatar leoafarias avatar lukaszkuciel avatar mamodom avatar ppicom avatar rinkstiekema avatar sgmonda avatar skalashnyk avatar skneko avatar smddzcy avatar talesmgodois avatar wovalle avatar yaroslavnekryach avatar z-hirschtritt avatar zdafs avatar zhirschtritt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.