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

refactor(d1): throw a better error if binding not found #60

Merged
merged 3 commits into from Mar 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/connectors/cloudflare-d1.ts
Expand Up @@ -5,7 +5,13 @@ export interface ConnectorOptions {
}

export default function sqliteConnector(options: ConnectorOptions) {
const getDB = () => globalThis.__cf_env__[options.bindingName];
const getDB = () => {
const binding = globalThis.__cf_env__?.[options.bindingName];
if (!binding) {
throw new Error(`D1 binding ${options.bindingName} not found`);
pi0 marked this conversation as resolved.
Show resolved Hide resolved
}
return binding;
}

return <Connector>{
name: "cloudflare-d1",
Expand Down