-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from skunkteam/update-multiple-docs-in-single-txn
feature: implement mask projection for all APIs and test multiple updates to a single document in transactions
- Loading branch information
Showing
13 changed files
with
175 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
- common-document-store-backend | ||
- UNIMPLEMENTED: run_aggregation_query is not supported yet | ||
- wao-claim-appengine-backend | ||
- UNIMPLEMENTED: mask is not supported yet | ||
- UNIMPLEMENTED: target_id should always be 1 is not supported yet | ||
- polis-soc-reg-backend - ??? |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use googleapis::google::firestore::v1::{structured_query, Document, DocumentMask}; | ||
use itertools::Itertools; | ||
|
||
use super::field_path::FieldReference; | ||
use crate::{document::StoredDocumentVersion, GenericDatabaseError}; | ||
|
||
#[derive(Debug)] | ||
pub struct Projection { | ||
fields: Vec<FieldReference>, | ||
} | ||
|
||
pub trait Project { | ||
fn project(&self, version: &StoredDocumentVersion) -> Document; | ||
} | ||
|
||
impl Project for Projection { | ||
fn project(&self, version: &StoredDocumentVersion) -> Document { | ||
let mut doc = Document { | ||
fields: Default::default(), | ||
create_time: Some(version.create_time.clone()), | ||
update_time: Some(version.update_time.clone()), | ||
name: version.name.to_string(), | ||
}; | ||
for field in &self.fields { | ||
match field { | ||
FieldReference::DocumentName => continue, | ||
FieldReference::FieldPath(path) => { | ||
if let Some(val) = path.get_value(&version.fields) { | ||
path.set_value(&mut doc.fields, val.clone()); | ||
} | ||
} | ||
} | ||
} | ||
doc | ||
} | ||
} | ||
|
||
impl Project for Option<Projection> { | ||
fn project(&self, version: &StoredDocumentVersion) -> Document { | ||
match self { | ||
Some(projection) => projection.project(version), | ||
None => version.to_document(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<structured_query::Projection> for Projection { | ||
type Error = GenericDatabaseError; | ||
|
||
fn try_from(value: structured_query::Projection) -> Result<Self, Self::Error> { | ||
let fields = value.fields.iter().map(TryInto::try_into).try_collect()?; | ||
Ok(Self { fields }) | ||
} | ||
} | ||
|
||
impl TryFrom<DocumentMask> for Projection { | ||
type Error = GenericDatabaseError; | ||
|
||
fn try_from(value: DocumentMask) -> Result<Self, Self::Error> { | ||
let fields = value.field_paths.iter().map(|s| s.parse()).try_collect()?; | ||
Ok(Self { fields }) | ||
} | ||
} |
Oops, something went wrong.