• search

Documentation

Firepit

Firepit is a fully featured ORM, loosley based on Sails JS. Click through to see example of how to define models and allow Firepit to structure your database project.

NPM downloads NPM version License

Before getting Started

If you are new to Firestore, please use of startup guide on how to create a project before using Firepit...

Initial Setup

It's easy to get started with Firepit

Creating a model

"One to many example"
firebase.firepit().createModel('role', {
  attributes: {
    name: {
      type: 'string',
      required: true,
    },
  },
});

firebase.firepit().createModel('user', {
  attributes: {
    name: {
      type: 'string',
      required: true,
    },
    roles: {
      hasMany: roles,
      via: 'name',
    },
  },
});

Create Records

"Quick example"
const Role = firepit().model('role');
const newRole = await Role.create({ name: administrator });

const User = firepit().model('user');
await User.create({ 'Joe Bloggs', roles: [...newRole.id] });

Populating Data

"Quick example"
const users = await User.find({}).populate('roles');

console.log(users);
//Output

{
  "id": "47gIS6WwWD3tqLJDyycN",
  "name": "Joe Bloggs",
  "roles": [
    {
      "id": "aq7PUv2dtH0au0hDjdjG",
      "name": "administrator",
      "createdAt": {
        "_seconds": 1538387482,
        "_nanoseconds": 531000000
      },
      "createdBy": "_SERVER_",
      "updatedAt": {
        "_seconds": 1538387482,
        "_nanoseconds": 531000000
      },
      "updatedBy": "_SERVER_"
    }
  ],
  "createdAt": {
    "_seconds": 1538387482,
    "_nanoseconds": 898000000
  },
  "createdBy": "_SERVER_",
  "updatedAt": {
    "_seconds": 1538387482,
    "_nanoseconds": 898000000
  },
  "updatedBy": "_SERVER_"
}