-
Notifications
You must be signed in to change notification settings - Fork 0
feat: v0.9.0 — null semantics (setNull, isNull filters, m2m set) + remove deprecated raw helpers #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: v0.9.0 — null semantics (setNull, isNull filters, m2m set) + remove deprecated raw helpers #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1353,6 +1353,7 @@ RETURNING * | |
| value is Map<String, dynamic> && | ||
| (value.containsKey('connect') || | ||
| value.containsKey('disconnect') || | ||
| value.containsKey('set') || | ||
| value.containsKey('create')); | ||
|
|
||
| /// Parent PK value known at compile time (from `data` on create or `where` | ||
|
|
@@ -1404,6 +1405,18 @@ RETURNING * | |
| final v = value as Map<String, dynamic>; | ||
|
|
||
| if (relation.type == RelationType.manyToMany) { | ||
| // `set`: replace the full relation — clear all junction rows for the | ||
| // parent, then connect exactly the given targets. | ||
| if (v.containsKey('set')) { | ||
| final clear = _compileJunctionClear(relation, parentId.toString()); | ||
| if (clear != null) mutations.add(clear); | ||
| mutations.addAll(_compileConnectOperations( | ||
| parentId: parentId.toString(), | ||
| relation: relation, | ||
| connectItems: _normalizeConnectDisconnect(v['set']), | ||
| effectiveSchema: effectiveSchema, | ||
|
Comment on lines
+1408
to
+1417
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Preserve primary-key types in relation mutations.
🤖 Prompt for AI Agents |
||
| )); | ||
|
Comment on lines
+1410
to
+1418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Validate every
🤖 Prompt for AI Agents |
||
| } | ||
| if (v.containsKey('connect')) { | ||
| mutations.addAll(_compileConnectOperations( | ||
| parentId: parentId.toString(), | ||
|
|
@@ -1422,6 +1435,13 @@ RETURNING * | |
| } | ||
| } else if (relation.type == RelationType.oneToMany || | ||
| relation.type == RelationType.oneToOne) { | ||
| if (v.containsKey('set')) { | ||
| throw UnsupportedError( | ||
| 'Nested `set` on the ${relation.type.name} relation ' | ||
| '"${entry.key}" is only supported for many-to-many relations ' | ||
| '(1:N re-parenting is not implemented).', | ||
| ); | ||
| } | ||
|
Comment on lines
1436
to
+1444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Reject The guard covers only 🤖 Prompt for AI Agents |
||
| // Nested create: child rows carry the FK back to the parent. | ||
| if (v.containsKey('create')) { | ||
| final creates = v['create']; | ||
|
|
@@ -1472,6 +1492,19 @@ RETURNING * | |
| return mutations; | ||
| } | ||
|
|
||
| /// DELETE all junction rows for [parentId] on an m2m relation (the clear | ||
| /// half of a nested `set`). Returns null when the relation lacks junction | ||
| /// metadata. | ||
| SqlQuery? _compileJunctionClear(RelationInfo relation, String parentId) { | ||
| if (relation.joinTable == null || relation.joinColumn == null) return null; | ||
| return SqlQuery( | ||
| sql: 'DELETE FROM ${_quoteIdentifier(relation.joinTable!)} ' | ||
| 'WHERE ${_quoteIdentifier(relation.joinColumn!)} = ${_placeholder(1)}', | ||
| args: [parentId], | ||
| argTypes: const [ArgType.string], | ||
| ); | ||
| } | ||
|
|
||
|
Comment on lines
+1495
to
+1507
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Fail loudly when many-to-many metadata is incomplete. This helper permits missing 🤖 Prompt for AI Agents |
||
| /// Normalize connect/disconnect input to a list of maps. | ||
| /// | ||
| /// Handles both single item and array formats: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Keep scalar
{set: ...}out of relation-op detection._atomicUpdateOptreats{set: 5}as a scalar assignment, but this change classifies it as a relation operation._compileCleanMainMutationthen drops scalar fields without relation metadata fromcleanData, silently omitting the update. Make relation detection context-aware before addingset.🤖 Prompt for AI Agents