Skip to content

Commit 057efba

Browse files
chenpercyPercy Chen
and
Percy Chen
authored
fix: Support querying hash data with 'not' condition (#95)
Co-authored-by: Percy Chen <[email protected]>
1 parent f00bc9d commit 057efba

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/encryption.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ function rewriteHashedFieldPath(
212212
hashField: string
213213
) {
214214
const items = path.split('.').reverse()
215-
// Special case for `where field equals` clause
216-
if (items.includes('where') && items[1] === field && items[0] === 'equals') {
215+
// Special case for `where field equals or not` clause
216+
if (items.includes('where') && items[1] === field && ['equals', 'not'].includes(items[0])) {
217217
items[1] = hashField
218218
return items.reverse().join('.')
219219
}

src/tests/integration.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,32 @@ describe.each(clients)('integration ($type)', ({ client }) => {
392392
expect(post).toBeNull()
393393
return
394394
}
395-
// Should be unreacheable
395+
// Should be unreachable
396396
const reached = true
397397
expect(reached).toBe(false)
398398
})
399+
399400
test("Doesn't work with the Fluent API", async () => {
400401
const posts = await client.user.findUnique({ where: { email } }).posts()
401402
for (const post of posts!) {
402403
expect(post.content).toMatch(cloakedStringRegex)
403404
}
404405
})
406+
407+
test("query entries with non-empty name", async () => {
408+
const fakeName = 'f@keU$er'
409+
await client.user.create({
410+
data: {
411+
name: '',
412+
413+
}
414+
});
415+
const users = await client.user.findMany();
416+
// assume active user with nonempty name
417+
const activeUserCount = await client.user.count({ where: { name: { not: '' } } })
418+
// use fakeName to pretend unique name
419+
const existingUsers = await client.user.findMany({ where: { name: { not: fakeName } } })
420+
expect(activeUserCount).toBe(users.length - 1);
421+
expect(existingUsers).toEqual(users);
422+
})
405423
})

src/visitor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function visitInputTargetFields<
8484
) {
8585
traverseTree(
8686
params.args,
87-
makeVisitor(models, visitor, ['equals', 'set'], debug.encryption),
87+
makeVisitor(models, visitor, ['equals', 'set', 'not'], debug.encryption),
8888
{
8989
currentModel: params.model!
9090
}

0 commit comments

Comments
 (0)