Add MATLAB compatibility and bulk document fetching#18
Merged
stevevanhooser merged 2 commits intomainfrom Mar 16, 2026
Merged
Conversation
- Add _matlab_compatible_props: unwraps single-element superclasses/depends_on lists to scalar dicts for MATLAB jsonencode compatibility - Add _normalize_loaded_props: inverse operation ensuring Python always sees lists - Update _do_add_doc to use _matlab_compatible_props when serializing - Update _do_get_doc to normalize props after deserialization - Override get_docs with efficient bulk SQL query (single SELECT ... IN) - Add get_docs_by_branch convenience method https://claude.ai/code/session_01GecDL1BqaAz3wJ7XiiAfg8
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the SQLite database implementation with MATLAB compatibility for JSON serialization and adds efficient bulk document fetching capabilities.
Key Changes
MATLAB JSON Compatibility: Added
_matlab_compatible_props()method that unwraps single-element lists to scalars before JSON serialization, matching MATLAB'sjsonencodebehavior so DID-matlab can read Python-created databases.Property Normalization: Added
_normalize_loaded_props()method that converts scalar values back to lists when loading documents, ensuring internal consistency regardless of the source database.Bulk Document Fetching: Implemented
get_docs()method that fetches multiple documents in a single SQL query instead of one-at-a-time, improving performance for batch operations. Supports:OnMissingparameter ("error", "warn", "ignore")Branch-based Retrieval: Added
get_docs_by_branch()convenience method to fetch all documents on a specific branch.Integration: Updated
_do_add_doc()to apply MATLAB-compatible formatting when storing documents, and_do_get_doc()to normalize loaded properties.Implementation Details
document_class.superclassesanddepends_onfields, which are the fields that MATLAB converts from cell arrays to scalars.WHERE doc_id IN (...)for safety and efficiency.get_docs()return a single Document object (not a list) for API convenience.https://claude.ai/code/session_01GecDL1BqaAz3wJ7XiiAfg8