1.5.1 • Published 3 months ago

firebase-collection v1.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

firebase-collection

A simple Firebase modeling library for managing collections with schema validation.

Installation

Install the package using npm:

npm install firebase-collection

Initialization

Initialize Firebase using the init function from the package

// commonjs
const firebase = require("firebase-collection");

// module
import firebase from "firebase-collection";

firebase.init({
    url: "your_firebase_realtime_database_url",
    service: "service_account ( type Object )"
})

Creating a Collection

Create a collection by instantiating the Collection class

const users = new firebase.Collection('users', {
  // Your collection schema
  name: String,
  age: Number
});

CRUD Operations

Perform CRUD operations on the collection

// Create a new record
const newUser = await users.create({ name: 'John Doe', age: 25 });

// Find all records
const allUsers = await users.findAll();

// Find a record by ID
const userById = await users.findById(newUser.__id);

// Find a record based on a filter
const filteredUser = await users.find({ name: 'John Doe' });

// Update a record by ID
await users.update(newUser.__id, { age: 26 });

// Delete a record by ID
await users.delete(newUser.__id);

// Delete a collection
await users.useDestroy();

Export

// commonjs
const { useExports } = require("firebase-collection");

// module
import { useExports } from "firebase-collection";

// use fs and path
useExports().then( metadata => {
    fs.writeFileSync( path.join( __dirname, 'export.json' ), metadata, { encoding:"utf8" });
})

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.4.6

3 months ago

1.5.1

3 months ago

1.5.0

3 months ago

1.4.9

3 months ago

1.4.8

3 months ago

1.4.7

3 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.4.2

5 months ago

1.4.1

5 months ago

1.4.0

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago