Skip to content

Commit

Permalink
validate $jsonArray dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarbounakis committed Feb 8, 2025
1 parent c26985b commit 1c5e8d1
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/SqliteFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,6 @@ class SqliteFormatter extends SqlFormatter {
// escape expr as field and waiting for parsing results as json array
return this.escape(expr);
}
if (Object.prototype.hasOwnProperty.call(expr, '$name')) {
return this.escape(expr);
}
if (Object.prototype.hasOwnProperty.call(expr, '$value')) {
if (Array.isArray(expr.$value)) {
return this.escape(JSON.stringify(expr.$value));
}
return this.escape(expr);
}
if (Object.prototype.hasOwnProperty.call(expr, '$literal')) {
if (Array.isArray(expr.$literal)) {
return this.escape(JSON.stringify(expr.$literal));
}
return this.escape(expr);
}
// trear expr as select expression
if (expr.$select) {
// get select fields
Expand All @@ -423,6 +408,23 @@ class SqliteFormatter extends SqlFormatter {
];
return `(${this.format(expr)})`;
}
// treat expression as query field
if (Object.prototype.hasOwnProperty.call(expr, '$name')) {
return this.escape(expr);
}
// treat expression as value
if (Object.prototype.hasOwnProperty.call(expr, '$value')) {
if (Array.isArray(expr.$value)) {
return this.escape(JSON.stringify(expr.$value));
}
return this.escape(expr);
}
if (Object.prototype.hasOwnProperty.call(expr, '$literal')) {
if (Array.isArray(expr.$literal)) {
return this.escape(JSON.stringify(expr.$literal));
}
return this.escape(expr);
}
throw new Error('Invalid json array expression. Expected a valid select expression');
}
}
Expand Down

0 comments on commit 1c5e8d1

Please sign in to comment.