How to use the firebase/database function in firebase

To help you get started, we’ve selected a few firebase 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 withspectrum / spectrum / src_old / db / notifications.js View on Github external
export const createNotifications = ({
  users,
  activityType,
  sender,
  content,
  ids = {},
}) => {
  const db = database();
  let updates = {};
  users.forEach(user => {
    try {
      const { key } = db.ref().child(`notifications/${user}`).push();
      updates[`notifications/${user}/${key}`] = {
        activityType,
        id: key,
        ids,
        sender,
        content,
        timestamp: database.ServerValue.TIMESTAMP,
        read: false,
      };
    } catch (err) {
      // Ignore if sending a notification to a single user fails
      console.log(err);
github withspectrum / spectrum / src / db / frequencies.js View on Github external
const getFrequencyBySlug = slug => {
  const db = database();

  return db
    .ref(`frequencies`)
    .orderByChild('slug')
    .equalTo(slug)
    .once('value')
    .then(snapshot => {
      const frequencies = snapshot.val();
      // We assume there is only one frequency with a given slug
      return frequencies[Object.keys(frequencies)[0]];
    });
};
github withspectrum / spectrum / src / db / auth.js View on Github external
export const saveProviderUid = (user: Object) => {
  const db = database();
  const updates = {};
  updates[`users/${user.uid}/providerUID`] = user.providerData[0].uid;
  return db.ref().update(updates).then(() => {});
};
github withspectrum / spectrum / src_old / db / stories.js View on Github external
export const createDraft = ({
  user: { displayName, photoURL, uid },
  frequencyId,
}: createDraftProps) => {
  const db = database();

  const ref = db.ref().child('stories').push();

  return ref
    .set({
      id: ref.key,
      published: false,
      timestamp: database.ServerValue.TIMESTAMP,
      frequencyId,
      creator: {
        displayName,
        photoURL,
        uid,
      },
      messages: {},
    })
github withspectrum / spectrum / src_old / db / messages.js View on Github external
export const getMessage = (
  type: MessageTypes,
  key: string
): GetMessageReturn => {
  const db = database();

  return db
    .ref(`${type}/${key}`)
    .once('value')
    .then(snapshot => snapshot.val());
};
github vigzmv / timetable-generator / src / re-base.js View on Github external
import Rebase from 're-base';
import firebase from 'firebase/app';
import database from 'firebase/database';

const app = firebase.initializeApp({
  apiKey: 'AIzaSyCz1sOB93i4OFudhJdfVflL_bVy_fhZiLs',
  authDomain: 'time-table-generator-separate.firebaseapp.com',
  databaseURL: 'https://time-table-generator-separate.firebaseio.com',
});

export default Rebase.createClass(database(app));
github gokulkrishh / anonymous-web / components / messages / index.js View on Github external
componentWillReceiveProps(nextProps) {
    if (nextProps.otherUserId && nextProps.chatURL) {
      this.firebaseRef = database().ref(`chats/${nextProps.chatURL}/messages`);
      if (typeof this.firebaseRefs["chats"] === "undefined") {
        this.bindAsArray(this.firebaseRef, "chats");
      }
    }
  }
github gokulkrishh / anonymous-web / components / input / index.js View on Github external
constructor(props) {
    super(props);
    this.firebaseDB = database();
    this.currentChat = null;
    this.timeoutRef = null;
    this.userInput = null;
    this.chatMessageRef = null;
    autoBind(this);
  }
github withspectrum / spectrum / src / db / communities.js View on Github external
const getCommunityBySlug = slug => {
  const db = database();

  return db
    .ref(`communities`)
    .orderByChild('slug')
    .equalTo(slug)
    .once('value')
    .then(snapshot => {
      const results = snapshot.val();
      return results[Object.keys(results)[0]];
    });
};
github withspectrum / spectrum / src / db / users.js View on Github external
export const getMessageGroups = uid => {
  const db = database();

  return db
    .ref(`/users/${uid}/messageGroups`)
    .once('value')
    .then(snapshot => snapshot.val());
};