Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ElenaMLopez/84a7977edbddc3e340b83e9299e0e9d3 to your computer and use it in GitHub Desktop.
Save ElenaMLopez/84a7977edbddc3e340b83e9299e0e9d3 to your computer and use it in GitHub Desktop.
Firebase Database API Cheatsheet.md
### FIREBASE API CHEATSHEET:

#### Introducción:
- No hay forma de almacenar un valor vacío de objeto/array o valor null.
- Tampoco exiten los arrays como tal, sino que se almacenan como un objeto cuyas claves son números (integer).
  (Si todas las claves son 'integers', firebase retornará un array).

#### Comprendiendo que es firebase
Básicamente es un arbol gigante de *hashes* con claves en forma de *string*.

Simplemente se escribe un valor en una localización, y la localización intermedias existiran automáticamente.
__ Clases __

** DataSnapshot : ** Contenedor para un subárbol de dats en una localización particular. La propiedad 'ref' almacena la Referencia a la localización del 'DataSnapshot'

Reference     : Represent a location.  Returned by:  db.ref(path), ref.parent, ref.child(path)
                Inherits query and read methods from Query, then adds write methods.

Query         : Query objects have query (sorting/filtering) methods and read methods.
                Query objects are returned when calling a query method on a Reference.
                The `ref` property stores a Reference to the Query's location.

You read from or write to a location using a Reference.
You begin a query at a location using a Reference's query methods, then read from it using the Query's read methods.
Read methods are callback-based, and pass DataSnapshots to the callback.

── Write Methods ──

push        (            )  Returns a Reference to a child location with an auto-generated key.
push        ( val,    cb )  Like `push()`, but also writes val to child location.
remove      (         cb )  Remove location.
set         ( val,    cb )  Writes val to location.                              Writing null == calling remove().
update      ( {vals}, cb )  Writes vals to their respective relative locations.  Writing null == calling remove().

── Query Methods ──

orderByChild    (key)       Order children at location by the value of specified grandchild key.
orderByKey      ()          Order children at location by child keys.
orderByValue    ()          Order children at location by child values.

limitToFirst    (num)       Max number of children to return from the beginning.  (Based on orderBy*.)
limitToLast     (num)       Max number of children to return from the end.        (Based on orderBy*.)
startAt         (val, key)  Return children who's val (and key, optionally) are >= the specified val (and key, optionally).
endAt           (val, key)  Return children who's val (and key, optionally) are <= the specified val (and key, optionally).
equalTo         (val)       Return children who's val is == the specified val.

── Read Methods ──

on           ( event, cb )  Invokes callback every time the specified event happens at location.
once         ( event, cb )  Like `on`, but only invokes the callback the first time the event happens.

── Events ──

child_added     Triggered once for each existing child, then when a new child is added.
child_changed   Triggered any time a child (including descendants) is modified.
child_moved     See docs.
child_removed   Triggered when an immediate child is removed.
value           Triggered once when listener attached, then every time the value (including children) changes.
@ElenaMLopez
Copy link
Author

FIREBASE API CHEATSHEET!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment