reference a value from other linked table2
This commit is contained in:
2
client
2
client
Submodule client updated: 4df0322e12...e104825edc
Submodule client-gui2 updated: 0461f0f602...f3ae817797
@@ -258,6 +258,11 @@ message PutTableDataRequest {
|
||||
// FAILED_PRECONDITION, instructing the caller to include X explicitly.
|
||||
//
|
||||
// Passing an empty map results in a no-op success response.
|
||||
// A LINK may be supplied as {"id": "42", "version": "2"} to explicitly
|
||||
// accept its target's current version, even when the row id is unchanged.
|
||||
// Both values must be positive integers. The server rejects a stale version
|
||||
// and atomically updates the saved FK version and all its stored linked values.
|
||||
// A plain unchanged row id preserves the previously saved version and values.
|
||||
map<string, google.protobuf.Value> data = 4;
|
||||
|
||||
// Required. Revision returned when this row was loaded or last saved.
|
||||
|
||||
Binary file not shown.
@@ -168,6 +168,11 @@ pub struct PutTableDataRequest {
|
||||
/// FAILED_PRECONDITION, instructing the caller to include X explicitly.
|
||||
///
|
||||
/// Passing an empty map results in a no-op success response.
|
||||
/// A LINK may be supplied as {"id": "42", "version": "2"} to explicitly
|
||||
/// accept its target's current version, even when the row id is unchanged.
|
||||
/// Both values must be positive integers. The server rejects a stale version
|
||||
/// and atomically updates the saved FK version and all its stored linked values.
|
||||
/// A plain unchanged row id preserves the previously saved version and values.
|
||||
#[prost(map = "string, message", tag = "4")]
|
||||
pub data: ::std::collections::HashMap<
|
||||
::prost::alloc::string::String,
|
||||
|
||||
@@ -59,10 +59,34 @@ pub fn convert_and_validate_data(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn accepted_link_value(id: i64, version: i64) -> Result<Value, String> {
|
||||
if id <= 0 || version <= 0 {
|
||||
return Err("Selected link id and version must be positive".into());
|
||||
}
|
||||
Ok(Value {
|
||||
kind: Some(Kind::StructValue(prost_types::Struct {
|
||||
fields: [
|
||||
("id".into(), Value { kind: Some(Kind::StringValue(id.to_string())) }),
|
||||
("version".into(), Value { kind: Some(Kind::StringValue(version.to_string())) }),
|
||||
].into(),
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn accepted_link_selection_keeps_full_precision() {
|
||||
let selected = accepted_link_value(i64::MAX, 3).unwrap();
|
||||
let Some(Kind::StructValue(fields)) = selected.kind else { panic!("Expected a link selection") };
|
||||
assert_eq!(fields.fields["id"].kind, Some(Kind::StringValue(i64::MAX.to_string())));
|
||||
assert_eq!(fields.fields["version"].kind, Some(Kind::StringValue("3".into())));
|
||||
assert!(accepted_link_value(0, 3).is_err());
|
||||
assert!(accepted_link_value(42, -1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_large_integers_and_decimals_as_strings() {
|
||||
assert_eq!(
|
||||
|
||||
2
server
2
server
Submodule server updated: 41a34de46f...81a49d66d6
Reference in New Issue
Block a user