Struct firebase_db_access::Firebase
source · pub struct Firebase { /* private fields */ }
Expand description
A Firebase instance to manage data.
Implementations
sourceimpl Firebase
impl Firebase
sourcepub fn new(url: &str) -> Result<Self, ParseError>
pub fn new(url: &str) -> Result<Self, ParseError>
Creates a new Firebase instance from the url of the fb server The url should be a valid HTTPS url, anything else will result in an error:
https://docs-examples.firebaseio.com/
Failures
- If a url is not specified with the HTTPS scheme, a
Err(ParseError::UrlIsNotHTTPS)
will be returned. - If a url cannot be parsed into a valid url then a
Err(ParseError::Parser(url::ParseError)
will be returned.
sourcepub fn from_url(url: &Url) -> Result<Self, ParseError>
pub fn from_url(url: &Url) -> Result<Self, ParseError>
Creates a firebase reference from a borrow of a Url instance.
Failures
- If a url is not specified with the HTTPS scheme, a
Err(ParseError::UrlIsNotHTTPS)
will be returned. - If a url cannot be parsed into a valid url then a
Err(ParseError::Parser(url::ParseError)
will be returned.
sourcepub fn authed(url: &str, auth_token: &str) -> Result<Self, ParseError>
pub fn authed(url: &str, auth_token: &str) -> Result<Self, ParseError>
Creates a new authenticated Firebase instance from the firebaseio url and an auth token.
Examples
let fb = Firebase::authed("https://myfb.firebaseio.com", "deadbeefcafe");
// The url shoud now be: https://myfb.firebaseio.com?auth=deadbeefcafe
Failures
- If a url is not specified with the HTTPS scheme, a
Err(ParseError::UrlIsNotHTTPS)
will be returned. - If a url cannot be parsed into a valid url then a
Err(ParseError::Parser(url::ParseError)
will be returned.
sourcepub fn at(&self, add_path: &str) -> Result<Self, ParseError>
pub fn at(&self, add_path: &str) -> Result<Self, ParseError>
Creates a new firebase instance that extends the path of an old firebase instance. Each time a reference is created a clone of the Firebase instance if done, all Firebase instances follow this immutable style.
#Examples
// Points to the root of the db ( / )
let fb = Firebase::new("https://myfb.firebaseio.com").unwrap();
// A new reference to /friends/yasha
let yasha = fb.at("/friends/yasha").unwrap();
// A new reference to /friends/yasha/messages
let messages = yasha.at("messages").unwrap();
sourcepub fn ops(&self, opts: &FbOps<'_>) -> FirebaseParams
pub fn ops(&self, opts: &FbOps<'_>) -> FirebaseParams
Creates a FirebaseParams instance, this instance has query parameters that are associated with it and that are used in every request made. Since query parameters only affect incomming data from Firebase, you can only GET data with a FirebaseParams instance.
This constructor takes in a FbOps struct to define all of its parameters, all undefined parameters can be omitted by extending the new FbOps struct by its default.
Examples
let fb = Firebase::new("https://db.fb.com").unwrap();
let query = fb.ops(&FbOps {
order_by: Some("Hello World"),
limit_to_first: Some(5),
end_at: Some(7),
equal_to: Some(3),
shallow: Some(true),
format: Some(true),
.. FbOps::default()
});
sourcepub fn get_url(&self) -> String
pub fn get_url(&self) -> String
Returns the current URL as a string that will be used to make the REST call when talking to Firebase.
sourcepub fn get(&self) -> Result<Response, i64>
pub fn get(&self) -> Result<Response, i64>
Gets data from Firebase.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let episode = firebase.at("/futurama/episodes/140").unwrap();
let info = episode.get();
sourcepub fn set(&self, data: HashMap<String, Data>) -> Result<Response, i64>
pub fn set(&self, data: HashMap<String, Data>) -> Result<Response, i64>
Sets data to Firebase.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let episode = firebase.at("/futurama/episodes/140/description").unwrap();
let info = episode.set("The Last Episode!");
sourcepub fn push(&self, data: HashMap<String, Data>) -> Result<Response, i64>
pub fn push(&self, data: HashMap<String, Data>) -> Result<Response, i64>
Pushes data to Firebase.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let episodes = firebase.at("/futurama/episodes").unwrap();
let info = episodes.push("The Lost Episode");
sourcepub fn update(&self, data: HashMap<String, Data>) -> Result<Response, i64>
pub fn update(&self, data: HashMap<String, Data>) -> Result<Response, i64>
Updates Firebase data.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let desc = firebase.at("/futurama/episodes/140/description").unwrap();
let info = desc.update("The Penultimate Episode!");
sourcepub fn remove(&self) -> Result<Response, i64>
pub fn remove(&self) -> Result<Response, i64>
Removes Firebase data.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let episode = firebase.at("/futurama/episodes/141").unwrap();
episode.remove();
sourcepub fn get_async<F>(&self, callback: F) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
pub fn get_async<F>(&self, callback: F) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
Asynchronous version of the get method, takes a callback and returns a handle to the thread making the request to Firebase.
Examples
let firebase = Firebase::new("https://shows.firebaseio.com").unwrap();
let desc = firebase.at("/futurama/episodes/141/description").unwrap();
let original = "The Lost Episode";
desc.get_async(move |result| {
if result.unwrap().body != original {
println!("The description changed!");
}
});
sourcepub fn set_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
S: Into<String>,
pub fn set_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
S: Into<String>,
Asynchronous version of the set method, takes a callback and returns a handle to the thread making the request to Firebase.
sourcepub fn push_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
pub fn push_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
Asynchronous version of the push method, takes a callback and returns a handle to the thread making the request to Firebase.
sourcepub fn update_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
pub fn update_async<S, F>(
&self,
data: HashMap<String, Data>,
callback: F
) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
Asynchronous version of the update method, takes a callback and returns a handle to the thread making the request to Firebase.
sourcepub fn remove_async<F>(&self, callback: F) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
pub fn remove_async<F>(&self, callback: F) -> JoinHandle<()>where
F: Fn(Result<Response, i64>) + Send + 'static,
Asynchronous version of the remove method, takes a callback and returns a handle to the thread making the request to Firebase. Todo remove all the empty hashes
sourcepub fn order_by(&self, key: &str) -> FirebaseParams
pub fn order_by(&self, key: &str) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and sorts this data by the key provided.
sourcepub fn limit_to_first(&self, count: u32) -> FirebaseParams
pub fn limit_to_first(&self, count: u32) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and limits the number of entries returned
on each request to the first count
. Often used with order_by
.
sourcepub fn limit_to_last(&self, count: u32) -> FirebaseParams
pub fn limit_to_last(&self, count: u32) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and limits the number of entries returned
on each request to the last count
. Often used with order_by
.
sourcepub fn start_at(&self, index: u32) -> FirebaseParams
pub fn start_at(&self, index: u32) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and only returns entries starting after
the specified index. Often used with order_by
.
sourcepub fn end_at(&self, index: u32) -> FirebaseParams
pub fn end_at(&self, index: u32) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and only returns entries appearing before
the specified index. Often used with order_by
.
sourcepub fn equal_to(&self, index: u32) -> FirebaseParams
pub fn equal_to(&self, index: u32) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and returns only the entry at the specified
index. Often used with order_by
.
sourcepub fn shallow(&self, flag: bool) -> FirebaseParams
pub fn shallow(&self, flag: bool) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and only returns a shallow copy of the db
in every request.
sourcepub fn format(&self) -> FirebaseParams
pub fn format(&self) -> FirebaseParams
Creates a FirebaseParams
instance, a Firebase struct that only
knows how to GET data, and formats the data to be exported in every
request. (e.g. includes a priority field).