firerust

Crates.iofirerust
lib.rsfirerust
version1.0.1
sourcesrc
created_at2022-04-15 17:05:38.821335
updated_at2022-04-15 18:44:06.030317
descriptionA simple library for Realtime Database of Firebase.
homepagehttps://github.com/danieldimbarre/Firerust.git
repositoryhttps://github.com/danieldimbarre/Firerust.git
max_upload_size
id568575
size78,586
Daniel Dimbarre (danieldimbarre)

documentation

README

Firerust

A very simple library to implement the Firebase real-time database in your code with the best performance

Instalation

Add this to your Cargo.toml:

[dependencies]
firerust = { version = "1" }

Usage

Import firerust

use firerust::FirebaseClient;

Initialize a Firebase client without auth

FirebaseClient::new("https:///<DATABASE_NAME>.firebaseio.com/")?;

Initialize a Firebase client with auth

let mut client = FirebaseClient::new("https:///<DATABASE_NAME>.firebaseio.com/")?;
client.auth("<ID_TOKEN>");

Examples

A basic example of data fetch:

use firerust::FirebaseClient;
use serde_json::Value;


let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?;
let reference = client.reference("/");

println!("{:?}", reference.get::<Value>());

A basic example of data set:

use firerust::FirebaseClient;


let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?;
let reference = client.reference("/");

reference.set(serde_json::json!({
    "message": "Setting data"
}))?;

A basic example of data update:

use firerust::FirebaseClient;


let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?;
let reference = client.reference("/");

reference.update(serde_json::json!({
    "message": "Updating data"
}))?;

A basic example of data deletion:

use firerust::FirebaseClient;


let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?;
let reference = client.reference("/");

reference.delete()?;

A snapshot event example:

use firerust::FirebaseClient;
use serde_json::Value;


let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?;
let reference = client.reference("/");

reference.on_snapshot(| data: Value | {
    println!("{:?}", data);

    Ok(())
})?;
Commit count: 0

cargo fmt