Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add BigInt as supported CursorType #91

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified prisma/db.test.sqlite
Binary file not shown.
6 changes: 6 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ model Category {
name String
posts Post[]
}

model BigIntCursorTest {
id BigInt @id
key String /// @encrypted
value Int
}
6 changes: 3 additions & 3 deletions src/dmmf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface DMMFModelDescriptor {

export type DMMFModels = Record<string, DMMFModelDescriptor> // key: model name

const supportedCursorTypes = ['Int', 'String']
const supportedCursorTypes = ['Int', 'String', 'BigInt']

export function analyseDMMF(input: DMMFDocument): DMMFModels {
const dmmf = dmmfDocumentParser.parse(input)
Expand All @@ -40,8 +40,8 @@ export function analyseDMMF(input: DMMFDocument): DMMFModels {
field =>
field.isUnique && supportedCursorTypes.includes(String(field.type))
)
const cursorField = model.fields.find(field =>
field.documentation?.includes('@encryption:cursor')
const cursorField = model.fields.find(
field => field.documentation?.includes('@encryption:cursor')
)
if (cursorField) {
// Make sure custom cursor field is valid
Expand Down
7 changes: 7 additions & 0 deletions src/tests/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ async function main() {
email: `spam+${Date.now()}@example.com`,
name: `Spam ${Date.now()}`
}
}),
client.bigIntCursorTest.create({
data: {
id: 1,
key: 'Answer to life, universe and everything',
value: 42
}
})
])
await migrate(client)
Expand Down
Loading