Skip to content

SODA: document model + insert + read by key (#200)#207

Merged
lemenkov merged 1 commit into
masterfrom
soda-2-documents-200
Jun 25, 2026
Merged

SODA: document model + insert + read by key (#200)#207
lemenkov merged 1 commit into
masterfrom
soda-2-documents-200

Conversation

@lemenkov

Copy link
Copy Markdown
Owner

Second step of the #163 SODA umbrella, on top of the collection foundation (#199). Adds the document layer over DBMS_SODA.

API (sync + async)

  • SodaDatabase.createDocument(content, key=None, mediaType="application/json") → a client-side SodaDocument (content may be a dict → JSON, str, or bytes).
  • SodaCollection.insertOne(doc) / insertOneAndGet(doc) → a SodaDocument with the server key / version / mediaType / createdOn / lastModified (no content, matching oracledb). Both accept a SodaDocument or a bare value.
  • SodaCollection.find().key(k).getOne() → read a document by key (None if absent). SodaOperation is the read-builder that QBE / multi-doc reads extend in SODA: query-by-example (QBE) find #201.
  • SodaDocument: getContent() (JSON → Python value) / getContentAsString() / getContentAsBytes(), plus the metadata fields.

Content size

Content binds as bytes, so inserting a document over the 32767-byte PL/SQL limit rides the transparent temp-LOB bind (#91). Reading content comes through one DBMS_LOB.SUBSTR and is capped at 32767 bytes — a larger stored document raises NotSupportedError rather than silently truncating (chunked large reads are a follow-up).

RE notes

  • get_created_on / get_last_modified return VARCHAR2 ISO strings, not timestamps (a to_char(…, datefmt) over them is ORA-06502 on 21c).
  • The default collection shape differs by server — 23ai native-JSON + embedded-OID RAW key (no tracked timestamps); 21c BLOB/JSON + UUID key + tracked timestamps. Both are covered by tests.
  • Depends on the NULL-OUT-bind fix (Fix decode crash on a NULL scalar OUT bind from a PL/SQL block (#205) #206, merged) — documents carry NULL fields.

Tests: offline document/content helpers; live insert + read-by-key + large-doc guard, sync + async — 23ai/21c pass, 11g/9i skip. Offline suite 526.

Closes #200

🤖 Generated with Claude Code

Second step of the #163 SODA umbrella, on top of the collection
foundation (#199). Adds the document layer over DBMS_SODA:

- SodaDatabase.createDocument(content, key=None, mediaType=...) builds a
  client-side SodaDocument; content may be a dict (-> JSON), str or bytes.
- SodaCollection.insertOne(doc) and insertOneAndGet(doc) -> a SodaDocument
  carrying the server key / version / media type / timestamps (no content,
  matching oracledb). Both accept a SodaDocument or a bare content value.
- SodaCollection.find().key(k).getOne() reads a document back by key
  (None if absent); SodaOperation is the read-builder that QBE / multi-doc
  reads extend in #201.
- SodaDocument: key / version / mediaType / createdOn / lastModified and
  getContent() (JSON -> Python value) / getContentAsString() /
  getContentAsBytes().

Content is bound as bytes, so inserting a document over the 32767-byte
PL/SQL limit rides the transparent temp-LOB bind (#91). Reading content
comes through one DBMS_LOB.SUBSTR and is capped at 32767 bytes — a larger
stored document raises NotSupportedError rather than silently truncating
(chunked large reads are a follow-up).

RE notes: get_created_on / get_last_modified return VARCHAR2 ISO strings
(not timestamps), and the default collection shape differs by server (23ai
native-JSON + embedded-OID key; 21c BLOB/JSON + UUID key + tracked
timestamps) — covered by tests on both. Sync + async; 23ai/21c pass,
11g/9i skip.

Closes #200

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
@lemenkov lemenkov added this to the 1.10.0 milestone Jun 25, 2026
@lemenkov lemenkov merged commit 66459f9 into master Jun 25, 2026
10 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.

SODA: document model + insert + read by key

1 participant