Helper library for working with znFirebase in Zengine backend plugins.
npm install @zenginehq/backend-firebase> Helper module for working with znFirebase in Zengine backend Plugins.
  
``bash`
npm i @zenginehq/backend-firebase --save
`js
var $firebase = require('@zenginehq/backend-firebase')();
var workspaceId = 11111;
// Load data.
$firebase.load(workspaceId).then(function (data) {
console.log('it works!', data);
// data fetched from
}).catch(function (err) {
console.error(err);
});
// Save data.
var dataObj = {
'childRoute': someData
// someData could be any data type,
// but dataObj (2nd argument of .save()) must be an object
}
$firebase.save(workspaceId, dataObj).then(function () {
console.log('success!');
// someData was saved at
}).catch(function (err) {
console.error(err);
});
// Delete data.
var recordId = 222
var deleteObj = {}
deleteObj[recordId] = null
$firebase.save(workspaceId, deleteObj).then(function () {
console.log('success!');
// the firebase route
// and all data it contained has been deleted
}).catch(function (err) {
console.error(err);
})
// Use arrays to formulate complex Firebase paths for both loading and saving.
var formId = 222
var recordId = 333
$firebase.load([workspaceId, formId, recordId, 'settings']).then(function (data) {
// This will expand to:
console.log('it works!', data);
}).catch(function (err) {
console.error(err);
});
// You can also pass a long string if that's your thing.
$firebase.load('foo/bar/baz/' + workspaceId + '/etc');
`
_Note about Deletions_
Passing null as the second argument of .save will cause strange and unhelpful behavior.null
Instead, pass an object with the endpoint(s) as the key(s) and as the value(s) for the second argument..update()
See Firebase docs for the underlying command that is called.
Ex:
`js
// much regrets
$firebase.save([workspaceId, 'undesiredField'], null).then(function () {
//etc...
})
// all the good vibes
$firebase.save(workspaceId, {'undesiredField': null}).then(function () {
// great work, team!
});
``