1.2.7 • Published 1 year ago

simple-firestore v1.2.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Simple Firestore

simple-firestore is a simple module to easily interact with Firestore, with optional caching!

Features

  • Super easy-to-use
  • Optional caching with Redis
  • Very customizable
  • Perfect for Discord Bots

Requirements

Installation

npm install simple-firestore
yarn add simple-firestore

Getting Started

Example

const SimpleFirestore = require("simple-firestore")

async function example() {

    const db = await SimpleFirestore({
        credentials: {
            apiKey: "<YOUR_API_KEY>",
            authDomain: "<YOUR_AUTH_DOMAIN>",
            projectId: "<YOUR_PROJECT_ID>",
            storageBucket: "<YOUR_STORAGE_BUCKET>",
            messagingSenderId: "<YOUR_MESSAGING_SENDER_ID>",
            appId: "<YOUR_APP_ID>"
        },
        useCache: true, 
        cacheTTL: 60*2, // seconds
        cachePrefix: "bot",
        logs: true
    })
}

example()

What is that?

  • credentials: these are the values you copy from your Firebase App
  • useCache: enabling this option will use Redis to cache the data you're getting from Firebase, in order to avoid high amounts of reads on your database
  • cacheTTL: the amount of time the data stays stored in cache (in seconds), this can be helpful for ensuring we don't waste resources on data that is not accessed often.
  • cachePrefix: this is useful if you're running different projects in the same Redis server, and want each project to have their own cache prefix
  • logs: receive logs on your terminal

Methods

.set(path, field, value, customTTL?)

This function adds/updates data in your database

await db.set("users/12345", "test", { foo: "bar", simple: "example" })

Using Dot Notation

await db.set("users/12345", "test.foo", "bar")

await db.set("users/12345", "test.simple", "example")

Using Custom TTL (optional)

await db.set("users/12345", "test", { foo: "bar", simple: "example" }, 60*10)

.get(path, field)

This function returns data from your database

await db.get("users/12345", "test")
// -> { foo: "bar", simple: "example" }

Using Dot Notation

await db.get("users/12345", "test.foo")
// -> "bar"

await db.get("users/12345", "test.simple")
// -> "example"

.deleteField(path, field)

This function deletes a specific field from a document

await db.deleteField("users/12345", "test")

.deleteDoc(path)

This function deletes a specific document from a collection

await db.deleteDoc("users/12345")
1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago