pyro v0.1.26
Overview
pyro provides a high level dsl for interacting with a Firebase datastore.
All pyro calls return promises.
How to use
pyro uses two environment variables: FIREBASE_ROOT and FIREBASE_KEY. FIREBASE_ROOT is
required. FIREBASE_KEY is only required for Firesbases with
security rules.
get
get is how you read data. You pass it the location to the data you want and it returns a promise.
The promise resolves with the value at the location you specified.
Below is an example:
NOTE The FIREBASE_ROOT and FIREBASE_KEY variables are set before we call require
var pyro = require('pyro')
pyro.
get('users/barney/friends/fred').
then(function (value) {
// Value is whatever data is stored at the /users/barney/friends/fred location
})set
set is how you insert and overwrite data. set assigns the value passed to the location specified. It
returns a promise that is resolved true when the value has been set. The location's priority is set
using the priority method.
Below is an example:
var pyro = require('pyro')
pyro.
set('questions/life the universe and everything', { answer: 42 }).
then(function (success) {
if (success)
do('...') // Ummm, I don't know, actually...
})add
add has the following behaviors:
- It only adds a value if one does not already exist at the specified location.
- It maintains a
countproperty alongisde added values.addassumes it is operating on a list.countprovides an easy way to know how many items exist in the list being added to.
Below is an example:
var pyro = require('pyro')
pyro.
add('users/fred/friends/barney', { years_known: 42 }).
then(function (added) {
if (added)
console.log('Recorded friend')
else
console.log('Friend already recorded, nothing to do')
})The result of this call (assuming it's the first of fred's friends we've added) would be:
/users/fred/friends/barney/{ years_known: 42 }
/count/1The following call:
var pyro = require('pyro')
pyro.
add('users/fred/friends/shemp', { years_known: -650000000 }).
then(function (added) {
if (added)
console.log('Recorded friend')
else
console.log('Friend already recorded, nothing to do')
})Would result in the following:
/users/fred/friends/barney/{ years_known: 42 }
/shemp/{ years_known: -650000000 }
/count/2priority
priority is used internally to set a location's priority. The default behavior is to return the value of Date.now(). If you need different behavior simply
override this method with a function that returns an appropriate value.
priority's signature is:
function priority(location, value) {
return // Value that can be used for sorting/searching
}The location parameter is the location being prioritized.
The value parameter is the value assigned to the location specified. touch does not pass this parameter.
touch
touch is how you modify a location's priority. The location's priority is set using the priority method.
touch passes the path it's working on to priority, but does not pass a value.
var pyro = require('pyro')
pyro.
touch('users/fred/friends/barney').
then(function (updated) {
if (updated)
celebrate()
}).
fail(function (err) {
console.log(err)
})increment_count
increment_count increments the count property for the specified location.
It first gets the current count (initializing it to 0 if it doesn't exist) and then
updates the count, incrementing it by one.
increment_count also sets a priority for the count using the priority method.
TODOS
- Add a
scopeproperty. This would be prepended to all locations so common location elements don't need to be repeated.
1 year ago
1 year ago
1 year ago
1 year ago
10 months ago
10 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago