Hi there...
Anyway, this should not be long. Many moons I was requested to work on a firebase wrap for ABM. Im not there yet, but this should be a start. I'm still getting a hang of it and more will follow as I make more progress. I'm testing this for something I'm doing, however you can use this for your webapps easily.
Some silly assumptions:
You can write some javascript code.
Steps
1. First things first, goto Firebase console and create an app https://console.firebase.google.com
2. Get your app ish together, appID, apiKey etc etc etc from google.
3. Now for some javascript, you can create an app.js file and link it to your html file... or perhaps execute this via websockets eval methods inside your ABM app.
4. Ensure that on the Rules tab you update the permissions to true for read and write and publish them.
Let's type ahead...
replace the stuff inside <> with your own details from the console. This I guess is to ensure that your firebase thing will work. Next we need to get reference to the db. Continue to type..
We want to store some records in a "table", let's create the table. The name is "recommendations". If the table does not exist, as soon as a record is added to it, it will come into existence.
We also want a way to return the last record added to the table, lets write a function..
This will return an object just like your Map object in b4j, or rather a JSON string like representation of your data.
Now, let's add a record to the table. You can link this with a button click event.
This creates a new record and pushes it to the list of records available and creates a unique key for it.
Now let's retrieve the last record we added to the table...
Off course, you can do whatever you want with it...
For now that concludes the C for create for our CRUD firebase functionality.
To be continued...
Anyway, this should not be long. Many moons I was requested to work on a firebase wrap for ABM. Im not there yet, but this should be a start. I'm still getting a hang of it and more will follow as I make more progress. I'm testing this for something I'm doing, however you can use this for your webapps easily.
Some silly assumptions:
You can write some javascript code.
Steps
1. First things first, goto Firebase console and create an app https://console.firebase.google.com
2. Get your app ish together, appID, apiKey etc etc etc from google.
3. Now for some javascript, you can create an app.js file and link it to your html file... or perhaps execute this via websockets eval methods inside your ABM app.
4. Ensure that on the Rules tab you update the permissions to true for read and write and publish them.
Let's type ahead...
B4X:
// Initialize Firebase
var fbconfig = {
apiKey: "<api-key>",
authDomain: "<domain>.firebaseapp.com",
databaseURL: "https://<db-thingy>.firebaseio.com",
projectId: "<projectid>",
storageBucket: "<storebucket>",
messagingSenderId: "<senderid>"
};
firebase.initializeApp(fbconfig);
replace the stuff inside <> with your own details from the console. This I guess is to ensure that your firebase thing will work. Next we need to get reference to the db. Continue to type..
B4X:
// Get a reference to the entire database
var fbdatabase = firebase.database().ref();
We want to store some records in a "table", let's create the table. The name is "recommendations". If the table does not exist, as soon as a record is added to it, it will come into existence.
B4X:
var recommendations = fbdatabase.child("recommendations");
We also want a way to return the last record added to the table, lets write a function..
B4X:
function GetLastrecommendations(){
var lastrec = new Object();
recommendations.limitToLast(1).on('child_added', function(childSnapshot) {
lastrec = childSnapshot.val();
});
return lastrec;
}
This will return an object just like your Map object in b4j, or rather a JSON string like representation of your data.
Now, let's add a record to the table. You can link this with a button click event.
B4X:
var record = new Object();
record.title = "Why I love B4J";
record.presenter = "Anele Mashy Mbanga";
record.link = "https://www.mbangas.com/blog/nothing_there";
var eRecord= JSON.stringify(record);
recommendations.push(eRecord);
This creates a new record and pushes it to the list of records available and creates a unique key for it.
Now let's retrieve the last record we added to the table...
B4X:
var lastrecommendation = GetLastrecommendations();
console.log(lastrecommendation);
Off course, you can do whatever you want with it...
For now that concludes the C for create for our CRUD firebase functionality.
To be continued...
Attachments
Last edited: