How to use @firebase/database - 2 common examples

To help you get started, we’ve selected a few @firebase/database examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firebase / firebase-admin-node / src / database / database.ts View on Github external
public getDatabase(url?: string): Database {
    const dbUrl: string = this.ensureUrl(url);
    if (!validator.isNonEmptyString(dbUrl)) {
      throw new FirebaseDatabaseError({
        code: 'invalid-argument',
        message: 'Database URL must be a valid, non-empty URL string.',
      });
    }

    let db: Database = this.INTERNAL.databases[dbUrl];
    if (typeof db === 'undefined') {
      const rtdb = require('@firebase/database');
      const { version } = require('../../package.json');
      db = rtdb.initStandalone(this.appInternal, dbUrl, version).instance;

      const rulesClient = new DatabaseRulesClient(this.app, dbUrl);
      db.getRules = () => {
        return rulesClient.getRules();
      };
      db.getRulesJSON = () => {
        return rulesClient.getRulesJSON();
      };
      db.setRules = (source) => {
        return rulesClient.setRules(source);
      };

      this.INTERNAL.databases[dbUrl] = db;
    }
    return db;
  }
github firebase / user-privacy / functions / node_modules / firebase-admin / lib / database / database.js View on Github external
DatabaseService.prototype.getDatabase = function (url) {
        var dbUrl = this.ensureUrl(url);
        if (!validator.isNonEmptyString(dbUrl)) {
            throw new error_1.FirebaseDatabaseError({
                code: 'invalid-argument',
                message: 'Database URL must be a valid, non-empty URL string.',
            });
        }
        var db = this.INTERNAL.databases[dbUrl];
        if (typeof db === 'undefined') {
            var rtdb = require('@firebase/database');
            db = rtdb.initStandalone(this.appInternal, dbUrl).instance;
            this.INTERNAL.databases[dbUrl] = db;
        }
        return db;
    };
    DatabaseService.prototype.ensureUrl = function (url) {

@firebase/database

This is the Firebase Realtime Database component of the Firebase JS SDK.

Apache-2.0
Latest version published 18 days ago

Package Health Score

95 / 100
Full package analysis

Popular @firebase/database functions