Backend Firebase
Helper module for working with znFirebase in Zengine backend Plugins.
Installation
npm i @zenginehq/backend-firebase --save
Usage
var $firebase = require('@zenginehq/backend-firebase')();
var workspaceId = 11111;
$firebase.load(workspaceId).then(function (data) {
console.log('it works!', data);
}).catch(function (err) {
console.error(err);
});
var dataObj = {
'childRoute': someData
}
$firebase.save(workspaceId, dataObj).then(function () {
console.log('success!');
}).catch(function (err) {
console.error(err);
});
var recordId = 222
var deleteObj = {}
deleteObj[recordId] = null
$firebase.save(workspaceId, deleteObj).then(function () {
console.log('success!');
}).catch(function (err) {
console.error(err);
})
var formId = 222
var recordId = 333
$firebase.load([workspaceId, formId, recordId, 'settings']).then(function (data) {
console.log('it works!', data);
}).catch(function (err) {
console.error(err);
});
$firebase.load('foo/bar/baz/' + workspaceId + '/etc');
Note about Deletions
Passing null
as the second argument of .save
will cause strange and unhelpful behavior.
Instead, pass an object with the endpoint(s) as the key(s) and null
as the value(s) for the second argument.
See Firebase docs for the underlying .update()
command that is called.
Ex:
$firebase.save([workspaceId, 'undesiredField'], null).then(function () {
})
$firebase.save(workspaceId, {'undesiredField': null}).then(function () {
});
Contributing
See contributing doc
API Docs
Full documentation