feat: add Object.create_if_absent atomic insert - #45
Merged
Merged
Conversation
v1 validates conflict_target=="id" and a non-empty id, then raises NotImplementedError so custom adapters fail loudly until implemented.
SQLite INSERT OR IGNORE, Postgres ON CONFLICT DO NOTHING RETURNING, Mongo insert_one/DuplicateKeyError, JsonDB path-lock, DynamoDB attribute_not_exists. CachingDatabase and ObservableDatabase forward.
Persists via Database.insert_if_absent (not save), rehydrates the stored winner on conflict, and flushes DeferredSaveMixin only when created.
SQLite/JsonDB concurrency, secondary-unique OR REPLACE hazard, wrapper forwarding, Mongo/Dynamo mocks, Object rehydrate/deferred flush, and Postgres integration cases.
Bump version.py to 0.0.20; document InsertIfAbsentResult and Object.create_if_absent in CHANGELOG, SPEC, stability, and entity-reference.
Benchmark comparisonThreshold: ±25% (informational, does not block merge)
|
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
Database.insert_if_absent/InsertIfAbsentResultacross SQLite, Postgres, MongoDB, JsonDB, DynamoDB, and cache/observable wrappers.Object.create_if_absentthat never routes through upsertsave(), returns(entity, created), and rehydrates the stored winner on conflict.idonly in v1; SQLite usesINSERT OR IGNORE(notOR REPLACE).0.0.20with changelog, stability, and entity-reference docs.Test plan
pytest tests/db/test_insert_if_absent.py tests/core/test_create_if_absent.pysave()upsert tests still greenMade with Cursor