drizzle-team / drizzle-team/drizzle-orm

[BUG]: When using `relations`, and drizzle proxy, an error is given when the result is an empty array.

Open
#4,113 1 comment 2 reactions 0 assignees View on GitHub
bug qb/crud rqb
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.39.3

### What version of `drizzle-kit` are you using?

0.30.4

### Other packages

_No response_

### Describe the Bug

### Issue
When using `relations`, and using the `query` function and `with` parameter, an error occurs when an empty array is returned by the proxy.

### Example
```ts
// proxy
export const db = drizzle(async (sql, params, method) => {
if (!process.env.CLOUDFLARE_DATABASE_ID) {
throw new Error("D1 Module failed to load due to undefined Database ID");
} else if (!process.env.CLOUDFLARE_ACCOUNT_ID) {
throw new Error("D1 Module failed to load due to undefined Account ID");
}

const res = await ResultAsync.fromPromise(
getCloudflare.d1.database.raw(process.env.CLOUDFLARE_DATABASE_ID, {
account_id: process.env.CLOUDFLARE_ACCOUNT_ID,
sql,
params
}), error => error as CloudflareError);

if (res.isErr()) {
console.error("[D1] Error from Cloudflare");
throw new Error("[D1]", res.error);
}

return { rows: res.value?.result[0]?.results?.rows ?? [] };
}, { schema });

// This function returns an error when db proxy returns { rows: [] }
db.query.user.findMany({
with: {
department: true
},
where: (user, { eq }) => eq(user.id, userId)
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.