Skip to content

Commit

Permalink
support for unary expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Gallinal committed Aug 13, 2022
1 parent 8382cfb commit 1257e97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/getParanoidSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ const updateNode = (node: AST | null) => {
node.args.value.forEach(({ ast }: { ast: AST }) => updateNode(ast));
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - no unary_expr type yet
if (node?.type === 'unary_expr') {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - no unary_expr type yet
updateNode(node.expr.ast);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - no else type yet
if (node?.type === 'else') {
Expand Down
9 changes: 9 additions & 0 deletions test/getParanoidSql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ test('select case when exists', () => {
);
});

test('select case when exists and when not exits', () => {
strictEqual(
getParanoidSql(
'SELECT CASE WHEN EXISTS (SELECT 1 FROM t) THEN 1 WHEN NOT EXISTS (SELECT 1 FROM u) THEN -1 ELSE 0 END',
),
'SELECT CASE WHEN EXISTS(SELECT 1 FROM `t` WHERE `t`.`deletedAt` IS NULL) THEN 1 WHEN NOT EXISTS (SELECT 1 FROM `u` WHERE `u`.`deletedAt` IS NULL) THEN -1 ELSE 0 END',
);
});

test('select case when exists with query in the end', () => {
strictEqual(
getParanoidSql(
Expand Down

0 comments on commit 1257e97

Please sign in to comment.