GithubHelp home page GithubHelp logo

firebase's Introduction

Firebase Realtime Database, introduction

Initial setup

1. Think about your data as a list of endpoints

like:

  • users/
  • users/id
  • messages
  • messages/id

Just like WP, but way more flexible. A tricky thing is that you can change the structure at any time, even by accident :)

2. Create a new project

https://console.firebase.google.com/u/0/

3. click Add Firebase to your web app

Copy the code to your html file

4. Click realtime database => Get started

5. Click Start in test mode => enable

Beware, this is not recommended for production, a database without authentication is a really bad idea

CRUD - Create, Read, Update, Delete

In our JS file, get a reference to the database

const database = firebase.database();

1. Create - Inserting data

https://firebase.google.com/docs/database/web/read-and-write?authuser=0

database.ref(path).push(obj)

e.g.

database.ref('users/').push({name:"Jonas", email: "jofh[at].kea.dk"})

2. Update - Overwrite existing data

Using .set() overwrites data at the specified location, including any child nodes.

database.ref(path).set(data);

e.g.

database.ref('users/someid').set({name: "Jonas Holbech", email:"jofh[at].kea.dk"});

3. Read - Get data

https://firebase.google.com/docs/database/web/lists-of-data?authuser=0#listen_for_child_events

database.ref(path).on(event, callback)

e.g.

database.ref('users/').on('child_added', snapshot=>{
    const key = snapshot.key;
    const data = snapshot.val();
});

4. Delete - Remove content

Deletes an "endpoint" and all children

database.ref(path).remove();

e.g.

database.ref('users/someid').remove()

Links:

firebase's People

Contributors

jonasholbech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.