Last active
October 9, 2021 02:34
-
-
Save dmurawsky/7f1548a21bcea062888d716ff30099f6 to your computer and use it in GitHub Desktop.
Example of Firebase v9 database functions vs Firebase v8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from "firebase/app"; | |
import "firebase/database"; | |
export const onceValue = <T>(path: string): Promise<Nullable<T>> => | |
firebase | |
.database() | |
.ref(path) | |
.once("value") | |
.then((snap) => snap.val()); | |
export const firebaseUpdate = (path: string, updateObj: Object) => firebase.database().ref(path).update(updateObj); | |
export const firebasePush = (path: string, object?: Object) => firebase.database().ref(path).push(object).key; | |
export const firebaseSet = (path: string, object: Object | string | number | boolean | null) => | |
firebase.database().ref(path).set(object); | |
export const firebaseDelete = (path: string) => firebase.database().ref(path).remove(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
getDatabase, | |
ref, | |
get, | |
update, | |
set, | |
push, | |
remove, | |
} from "firebase/database"; | |
const getRef = (path: string) => ref(getDatabase(), path); | |
export const onceValue = <T>(path: string): Promise<T | null> => get(getRef(path)).then((snap) => snap.val()); | |
export const firebaseUpdate = (path: string, updateObj: Object) => update(getRef(path), updateObj); | |
export const firebasePush = (path: string, object?: Object) => push(getRef(path), object).key; | |
export const firebaseSet = (path: string, object: Object | string | number | boolean | null) => | |
set(getRef(path), object); | |
export const firebaseDelete = (path: string) => remove(getRef(path)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment