pub struct Collection<T>where
T: Serialize + DeserializeOwned + 'static,{ /* private fields */ }
Expand description
Represents a collection of documents in a Firestore database.
Documents in Firestore do not have types, but on the Rust end, we associate each collection with a type. Documents are serialized into and deserialized from this type when writing/reading to Firestore.
Implementations§
Source§impl<T> Collection<T>
impl<T> Collection<T>
Sourcepub fn new(db: SharedFirestoreClient, name: CollectionName) -> Self
pub fn new(db: SharedFirestoreClient, name: CollectionName) -> Self
Construct a top-level collection (i.e. a collection whose parent is the root.)
Sourcepub fn list(&self) -> ListResponse<T>
pub fn list(&self) -> ListResponse<T>
Returns a stream of all of the documents in a collection (as [NamedDocument]s).
pub fn name(&self) -> CollectionName
pub fn subcollection<S>(&self, name: &str, collection: &str) -> Collection<S>
Sourcepub async fn create_with_key(
&self,
ob: &T,
key: impl QualifyDocumentName,
) -> Result<()>
pub async fn create_with_key( &self, ob: &T, key: impl QualifyDocumentName, ) -> Result<()>
Create the given document in this collection with the given key.
Returns an error if the key is already in use (if you intend to replace the
document in that case, use upsert
instead.)
Sourcepub async fn try_create(
&self,
ob: &T,
key: impl QualifyDocumentName,
) -> Result<bool>
pub async fn try_create( &self, ob: &T, key: impl QualifyDocumentName, ) -> Result<bool>
Create the given document in this collection with the given key.
Returns true
if the document was created, or false
if it already existed.
Sourcepub async fn create(&self, ob: &T) -> Result<DocumentName>
pub async fn create(&self, ob: &T) -> Result<DocumentName>
Add the given document to this collection, assigning it a new key at random.
Sourcepub async fn upsert(&self, ob: &T, key: impl QualifyDocumentName) -> Result<()>
pub async fn upsert(&self, ob: &T, key: impl QualifyDocumentName) -> Result<()>
Overwrite the given document to this collection, creating a new document if one does not exist.
Sourcepub async fn update(&self, ob: &T, key: impl QualifyDocumentName) -> Result<()>
pub async fn update(&self, ob: &T, key: impl QualifyDocumentName) -> Result<()>
Update the given document, returning an error if it does not exist.
Sourcepub async fn get(&self, key: impl QualifyDocumentName) -> Result<T>
pub async fn get(&self, key: impl QualifyDocumentName) -> Result<T>
Get the document with a given key.
Sourcepub async fn delete(&self, key: impl QualifyDocumentName) -> Result<()>
pub async fn delete(&self, key: impl QualifyDocumentName) -> Result<()>
Delete the document with a given key.
Auto Trait Implementations§
impl<T> Freeze for Collection<T>
impl<T> !RefUnwindSafe for Collection<T>
impl<T> Send for Collection<T>where
T: Send,
impl<T> Sync for Collection<T>where
T: Sync,
impl<T> Unpin for Collection<T>where
T: Unpin,
impl<T> !UnwindSafe for Collection<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request