Skip to content

Commit

Permalink
try with original sql on failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Sep 6, 2024
1 parent e1fe15a commit 15b5f44
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/typegen/src/query/analyze-select-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,20 @@ export const analyzeSelectStatement = async (
await tx.any(AnalyzeSelectStatementColumnsQuery(selectStatementSql)),
)

if (results.length === 1 && results[0].error_message) {
// try the original sql
// todo: more efficient way to do this?
results = SelectStatementAnalyzedColumnSchema.array().parse(
await tx.any(AnalyzeSelectStatementColumnsQuery(modifiedAST.originalSql)),
)
}

for (const r of results) {
if (r.error_message) {
// todo: start warning or delete this. let's see what kind of warnings the tests yield first
// or, maybe, make it logger.debug and show these with the `--debug` flag
// and/or have a `--strict` flag that errors when there are any warnings - making this a kind of sql validator tool which is cool
// console.warn(`Error analyzing select statement: ${r.error_message}`)
// console.warn(`Error analyzing select statement: ${r.error_message}`, modifiedAST.originalSql)
}
}

Expand Down

0 comments on commit 15b5f44

Please sign in to comment.