Skip to content

Conversation

@RoDmitry
Copy link
Collaborator

@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.

@RoDmitry RoDmitry force-pushed the partial_document branch 2 times, most recently from 8e44901 to 365c353 Compare September 16, 2025 14:35
@RoDmitry RoDmitry changed the title Partial document Partial document struct for updates Sep 17, 2025
@haydenhoang
Copy link
Contributor

The partial struct derive is neat!

I couldn't think of any good use cases for collection_schemaless .update() and .create() other than consistency, the user might expect collection_schemaless to have those two methods. All in all, I think it's not worth implementing.

Also I don't know if id is updatable.

id is not updatable

@RoDmitry RoDmitry marked this pull request as ready for review October 16, 2025 14:16
@RoDmitry
Copy link
Collaborator Author

@haydenhoang check it out. Does it look good?

@RoDmitry
Copy link
Collaborator Author

RoDmitry commented Oct 16, 2025

Added a trick to comment an auto-generated code in mustache, if allParams is empty. Otherwise vendorExtensions was not accessible. Did not find any better solution to avoid empty structs.

This fix is about vendor extension scoping problem
@haydenhoang
Copy link
Contributor

haydenhoang commented Oct 16, 2025

This looks good! But we need to re-add tests for the bulk documents operations: import, export, bulk update and bulk delete tests

@RoDmitry
Copy link
Collaborator Author

RoDmitry commented Oct 17, 2025

I did not notice that strongly-typed representation tests are different. I thought it's a copy of schemaless. Can you check them? I'm not that good at writing tests. I have left them commented in typesense/tests/client/documents_test.rs.

Also I'm thinking that maybe jsonl methods (import_jsonl, export) are not for everybody. I can see them useful in exporting to file, and then importing it back without parsing. But I think it would be also useful to have methods that take &[Document] as input, and join them with '\n' internally. Also I guess jsonl export must be called export_jsonl.

@haydenhoang
Copy link
Contributor

But I think it would be also useful to have methods that take &[Document] as input, and join them with '\n' internally. Also I guess jsonl export must be called export_jsonl.

Yes, let's implement this in another PR.

Will add those missing tests shortly.

…e and bulk delete

Also renamed `documents().export()` to `export_jsonl()`
@haydenhoang
Copy link
Contributor

This is ready for merge!

@RoDmitry RoDmitry requested a review from morenol October 17, 2025 17:34
@RoDmitry
Copy link
Collaborator Author

Can't merge my own PR using the button.

@RoDmitry RoDmitry merged commit 2d89530 into typesense:main Oct 17, 2025
3 checks passed
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.

3 participants