Skip to content

Add MATLAB compatibility and bulk document fetching#18

Merged
stevevanhooser merged 2 commits intomainfrom
claude/add-matlab-props-method-1rSyY
Mar 16, 2026
Merged

Add MATLAB compatibility and bulk document fetching#18
stevevanhooser merged 2 commits intomainfrom
claude/add-matlab-props-method-1rSyY

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

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's jsonencode behavior 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:

    • Single or multiple document IDs
    • Branch filtering
    • Error handling with OnMissing parameter ("error", "warn", "ignore")
    • Preserves original document ID order
  • 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

  • The MATLAB compatibility layer specifically handles document_class.superclasses and depends_on fields, which are the fields that MATLAB converts from cell arrays to scalars.
  • The bulk fetch uses parameterized SQL queries with WHERE doc_id IN (...) for safety and efficiency.
  • Single document ID requests to get_docs() return a single Document object (not a list) for API convenience.

https://claude.ai/code/session_01GecDL1BqaAz3wJ7XiiAfg8

claude added 2 commits March 16, 2026 09:07
- 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
@stevevanhooser stevevanhooser merged commit 1309b99 into main Mar 16, 2026
4 checks passed
@stevevanhooser stevevanhooser deleted the claude/add-matlab-props-method-1rSyY branch March 16, 2026 09:20
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