Skip to content

Commit fae884d

Browse files
committed
fix update code whoops
1 parent 008cbba commit fae884d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/lib/src/compiler.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ export class SqlCompilerImpl implements SqlCompiler {
2222
* @param statement SQL statement to compile
2323
* @returns Array of MongoDB commands
2424
*/
25+
// Store the current SQL statement metadata for use in helper methods
26+
private currentStatementMetadata: any;
27+
2528
compile(statement: SqlStatement): Command[] {
2629
const ast = statement.ast;
2730

31+
// Access statement metadata which includes the nested field replacements
32+
this.currentStatementMetadata = statement.metadata;
33+
log('Statement metadata:', JSON.stringify(this.currentStatementMetadata, null, 2));
34+
2835
log('Compiling SQL AST:', JSON.stringify(ast, null, 2));
2936

3037
// Pre-process the AST to handle nested fields that might be parsed as table references
@@ -424,10 +431,21 @@ export class SqlCompilerImpl implements SqlCompiler {
424431
// This requires accessing the parser's replacements, which we don't have direct access to
425432
// Instead, we'll need to restore it through other means
426433

427-
// For now, we'll assume shipping.address.country.name for demonstration
428-
// In a real implementation, we'd need to pass the replacements from parser to compiler
429-
fieldName = 'shipping.address.country.name';
430-
log(`Restored nested field from placeholder: ${setItem.column} -> ${fieldName}`);
434+
// Extract the original nested field path using metadata from the statement
435+
436+
// Get the metadata with nested field replacements from the statement
437+
const nestedFieldReplacements = this.currentStatementMetadata?.nestedFieldReplacements;
438+
439+
// Check if we have metadata containing the field replacements
440+
if (nestedFieldReplacements && nestedFieldReplacements.length > placeholderIndex) {
441+
const [_, originalField] = nestedFieldReplacements[placeholderIndex];
442+
fieldName = originalField;
443+
log(`Restored nested field from metadata: ${setItem.column} -> ${fieldName}`);
444+
} else {
445+
// Fallback to using the placeholder itself if we can't restore it
446+
fieldName = setItem.column;
447+
log(`Could not restore nested field, using placeholder: ${fieldName}`);
448+
}
431449
}
432450
// Special handling for nested fields in UPDATE statements
433451
else if (setItem.table) {

0 commit comments

Comments
 (0)