Skip to content

Conversation

RoDmitry
Copy link
Contributor

@RoDmitry RoDmitry commented Sep 15, 2025

Auto-generates a partial document struct for updates. To avoid serde_json::Value as an input.

#[derive(typesense::Typesense, Serialize, Deserialize, Debug, PartialEq, Clone)]
struct Book {
    id: String,
    title: String,
    author: String,
    publication_year: i32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    in_stock: Option<bool>,
}
let partial_update_struct = BookPartial {
    publication_year: Some(1966),
    in_stock: Some(Some(false)),
    ..Default::default()
};
let updated_book = typed_collection
    .document(&book_1.id)
    .update(&partial_update_struct, None)
    .await
    .expect("Failed to update typed document");

Derive macro creates struct BookPartial with all optional fields.

@haydenhoang what do you think? Need help with deciding about collection_schemaless tests (in typesense/tests/client/documents_test.rs). Do you need collection_schemaless updates and creates? As you know I hate serde_json::Value. Is there any point in implementing it?

Also I don't know if id is updatable.
And is there a reason to have Option<Option<bool>> for updates, or should it be Option<bool>?

haydenhoang and others added 30 commits August 31, 2025 13:54
@RoDmitry RoDmitry changed the title Partial document Partial document struct for updates Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants