Skip to content

Commit bb5f60f

Browse files
Simon HoßSimon Hoß
authored andcommitted
fix not null
1 parent 7fab5d0 commit bb5f60f

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

lib/query/compiler.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,12 @@ class DynamoDBQueryCompiler extends QueryCompiler {
107107
}
108108
else if (whereItem.type === "whereNull") {
109109
scanParam.ExpressionAttributeValues[`:column_${columnCount}`] = null;
110-
let functionName = "attribute_not_exists";
111110
if (whereItem.not) {
112-
filterExpression += `(#column_${columnCount} <> :column_${columnCount}`;
113-
functionName = "attribute_exists";
111+
filterExpression += `(#column_${columnCount} <> :column_${columnCount} and attribute_exists(#column_${columnCount}))`;
114112
}
115113
else {
116-
filterExpression += `(#column_${columnCount} = :column_${columnCount}`;
114+
filterExpression += `(#column_${columnCount} = :column_${columnCount} or attribute_not_exists(#column_${columnCount}))`;
117115
}
118-
filterExpression += ` or ${functionName}(#column_${columnCount}))`;
119116
}
120117
else if (whereItem.type === "whereBetween") {
121118
scanParam.ExpressionAttributeValues[`:column_${columnCount}`] =

src/query/compiler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,11 @@ export class DynamoDBQueryCompiler extends (QueryCompiler as any) {
119119
} else if (whereItem.type === "whereNull") {
120120
scanParam.ExpressionAttributeValues[`:column_${columnCount}`] = null;
121121

122-
let functionName = "attribute_not_exists";
123122
if (whereItem.not) {
124-
filterExpression += `(#column_${columnCount} <> :column_${columnCount}`;
125-
functionName = "attribute_exists";
123+
filterExpression += `(#column_${columnCount} <> :column_${columnCount} and attribute_exists(#column_${columnCount}))`;
126124
} else {
127-
filterExpression += `(#column_${columnCount} = :column_${columnCount}`;
125+
filterExpression += `(#column_${columnCount} = :column_${columnCount} or attribute_not_exists(#column_${columnCount}))`;
128126
}
129-
130-
filterExpression += ` or ${functionName}(#column_${columnCount}))`;
131127
} else if (whereItem.type === "whereBetween") {
132128
scanParam.ExpressionAttributeValues[`:column_${columnCount}`] =
133129
whereItem.value[0];

test/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("when select", () => {
9696
},
9797
ProjectionExpression: "#project_0, #project_1",
9898
FilterExpression:
99-
"(#column_0 <> :column_0 or attribute_exists(#column_0))",
99+
"(#column_0 <> :column_0 and attribute_exists(#column_0))",
100100
TableName: "test_test_table"
101101
},
102102
expect.anything()

0 commit comments

Comments
 (0)