3.6.1 • Published 2 years ago

jovo-db-firestore v3.6.1

Weekly downloads
128
License
Apache-2.0
Repository
-
Last release
2 years ago

Google Firestore Database Integration

To view this page on the Jovo website, visit https://v3.jovo.tech/marketplace/jovo-db-firestore

Learn how to store user specific data of your Alexa Skills and Google Actions to Google Cloud Firestore.

Tutorial: Deploy to Google Cloud

Introduction

The Firestore integration allows you to store user session data in the NoSQL service running on Google Firebase. This integration is especially convenient if you're running your voice app on Google Cloud Functions. You can find the official documentation about Firestore here: firebase.google.com/docs/firestore.

Learn more about hosting your application on Google Cloud Functions.

Configuration

Download the package like this:

$ npm install --save jovo-db-firestore

Firestore can be enabled in the src/app.js file like this:

// @language=javascript

// src/app.js

const { Firestore } = require('jovo-db-firestore');

// Enable DB after app initialization
app.use(new Firestore());

// @language=typescript

// src/app.ts

import { Firestore } from 'jovo-db-firestore';

// Enable DB after app initialization
app.use(new Firestore());

If you are using Firestore in other parts of your application and already have an intialized instance, you can just pass that into the constructor as well. This is especially helpful when using Firebase Cloud Functions. When deploying your code to Firebase Cloud Functions you don't need to provide the databaseURL and credential in the config.js file and you won't have the error related to the initializeApp method being called twice on the firebase-admin instance.

// @language=javascript

// src/app.js

const { Firestore } = require('jovo-db-firestore');

// Firebase admin and firestore initialization code
const admin = require('firebase-admin');
admin.initializeApp();
let db = admin.firestore();

// Enable DB after app initialization
app.use(new Firestore({}, db));

// @language=typescript

// src/app.ts

import { Firestore } from 'jovo-db-firestore';

// Firebase admin and firestore initialization code
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();

// Enable DB after app initialization
app.use(new Firestore({}, db));

Inside your config.js file you have to set your credential and your databaseURL. You can also optionally set the collection name (default is UserData):

// @language=javascript

// src/config.js

module.exports = {
    
    db: {
        Firestore: {
            credential: require('<path-to-credential-json-file>'),
            databaseURL: '<databaseURL>',
            collectionName: '<collectionName>',
        },
    },

    // ...

};

// @language=typescript

// src/config.ts

const config = {
    
    db: {
        Firestore: {
            credential: require('<path-to-credential-json-file>'),
            databaseURL: '<databaseURL>',
            collectionName: '<collectionName>',
        },
    },

    // ...

};

Using Firestore outside Google Cloud

If you use plan to use the Firestore integration while hosting your project outside Google Cloud Functions (e.g. on AWS Lambda), you have to add the following post install script to your package.json:

"scripts": {
  "postinstall": "npm install grpc --target=<function-node-version> --target_arch=x64 --target_platform=linux --target_libc=glibc"
},

You need the script because the Firestore integration depends on the firebase-admin module, which depends on the grpc module. If you simply run npm install it will download the grpc binary for your node version and operating system combination, which might differ from the one Lambda expects, which is node-v48-linux-x64-glibc. The script installs the correct binary for you. Find more about that here.

3.6.1

2 years ago

3.6.0

2 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.0

4 years ago

3.0.22

4 years ago

3.0.21

4 years ago

3.0.20

4 years ago

3.0.19

4 years ago

3.0.18

4 years ago

3.0.17

4 years ago

3.0.16

4 years ago

3.0.15

4 years ago

3.0.14

4 years ago

3.0.13

4 years ago

3.0.12

4 years ago

3.0.10

4 years ago

3.0.11

4 years ago

3.0.9

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.4

4 years ago

3.0.5

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.2.21

4 years ago

2.2.20

4 years ago

2.2.18

4 years ago

2.2.17

4 years ago

2.2.15

5 years ago

2.2.14

5 years ago

2.2.13

5 years ago

2.2.12

5 years ago

2.2.11

5 years ago

2.2.10

5 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago