Skip to content

Commit

Permalink
code-gen: fix deletedAt check with Date in the future (#483)
Browse files Browse the repository at this point in the history
Closes #482
  • Loading branch information
dirkdev98 authored Nov 7, 2020
1 parent 82d830f commit d2d8d51
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/code-gen/src/generator/sql/where-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function getWherePartial(context, type) {
if (field.variant === "includeNotNull") {
str += `
if ((where.${field.name} ?? false) === false) {
strings.push(\` AND $\{tableName}"${field.key}" IS NULL \`);
strings.push(\` AND ($\{tableName}"${field.key}" IS NULL OR $\{tableName}"${field.key}" > now()) \`);
values.push(undefined);
}
`;
Expand Down
15 changes: 15 additions & 0 deletions packages/code-gen/test/sql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ test("code-gen/e2e/sql", async (t) => {
}
});

t.test("deletedAt in the future", async (t) => {
const future = new Date();
future.setUTCDate(future.getUTCDate() + 1);
const [user] = await client.queries.userInsert(sql, {
nickName: "Foo",
email: "[email protected]",
authKey: uuid(),
deletedAt: future,
});
const [selectUser] = await client.queries.userSelect(sql, { id: user.id });

t.ok(selectUser);
t.deepEqual(selectUser.deletedAt, future);
});

t.test("destroy test db", async (t) => {
await cleanupTestPostgresDatabase(sql);
t.ok(true);
Expand Down
12 changes: 9 additions & 3 deletions packages/store/src/generated/query-partials.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2d8d51

Please sign in to comment.