Skip to content

Commit

Permalink
[drizzle] improve handling of null cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Sep 10, 2024
1 parent 9f4ef55 commit 0aadded
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-years-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pothos/plugin-drizzle": patch
---

improve handling of null cursor values
6 changes: 5 additions & 1 deletion packages/plugin-drizzle/src/utils/cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const DEFAULT_MAX_SIZE = 100;
const DEFAULT_SIZE = 20;

export function formatCursorChunk(value: unknown) {
if (value == null) {
return null;
}

if (value instanceof Date) {
return `D:${String(Number(value))}`;
}
Expand Down Expand Up @@ -86,7 +90,7 @@ export function getColumnSerializer(fields: Column[], config: PothosDrizzleSchem
return `J:${JSON.stringify(fields.map((col) => value[config.columnToTsName(col)]))}`;
}

return `${formatCursorChunk(value[config.columnToTsName(fields[0])])}`;
return formatCursorChunk(value[config.columnToTsName(fields[0])]);
};
}

Expand Down

0 comments on commit 0aadded

Please sign in to comment.