Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the names of tables of my firebase database in ionic 2 [closed]

Is there any solution that allow me to get the name of tables of my database as shown in the picture

database structure

like image 403
Ali H Avatar asked Oct 18 '25 15:10

Ali H


1 Answers

You could try something like this:

firebase.database().ref().once('value', function(snapshot) {
    if (snapshot.val() !== null) {
        var tableNames = Object.keys(snapshot.val());
        console.log(tableNames); // ["answers", "blocks", "chats", "classes"]
    }
});

So that gets that whole database and then gets the top level keys from the returned object.

References:

https://firebase.google.com/docs/database/web/read-and-write#read_data_once

In some cases you may want a snapshot of your data without listening for changes, such as when initializing a UI element that you don't expect to change. You can use the once() method to simplify this scenario: it triggers once and then does not trigger again.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

The Object.keys() method returns an array of a given object's own enumerable properties

like image 67
camden_kid Avatar answered Oct 21 '25 01:10

camden_kid