Jk3ndo
Jk3ndo
CDCloudflare Developers
Created by Jk3ndo on 4/22/2025 in #workers-help
Cloudflare D1 Database is not recognized as it inside a worker
Hello guys, I have created a worker which helps me to execute a cron which read data from a specific KV, and for each of those data make an API call and save the result into a database. The response saved match the following interface:
export interface IWebsiteVerificationReport {
domain: string,
slug: string,
verification: string,
status: boolean,
message: string,
sanityDocId: string,
audience: string,
location?: string,
runAt?: Date
}
export interface IWebsiteVerificationReport {
domain: string,
slug: string,
verification: string,
status: boolean,
message: string,
sanityDocId: string,
audience: string,
location?: string,
runAt?: Date
}
I have created a class to handle the database related operations and it was working very well. see database file. So as I said it was working very well, but as API call was too much I decided to include a Durable object to execute my API calls in queue. I added then the following line to the entry point file:
export { RequestQueue } from "./storage/requestQueue";
export { RequestQueue } from "./storage/requestQueue";
And for my d1 and durable object configuration in my wrangler toml I added those lines:
durable_objects.bindings = [{ name = "REQUEST_QUEUE", class_name = "RequestQueue" }]

d1_databases = [
{ binding = "DB", database_name = "lightmode-store", database_id = "c1766ce5-234c-401b-a854-d614c5c1d300" },
]

[[migrations]]
tag = "v1"
new_classes = ["RequestQueue"]
new_databases = ["lightmode-store"]
durable_objects.bindings = [{ name = "REQUEST_QUEUE", class_name = "RequestQueue" }]

d1_databases = [
{ binding = "DB", database_name = "lightmode-store", database_id = "c1766ce5-234c-401b-a854-d614c5c1d300" },
]

[[migrations]]
tag = "v1"
new_classes = ["RequestQueue"]
new_databases = ["lightmode-store"]
However, after having added the durable object to it, at the step of the database insertion data I get the error "Error: TypeError: dba.prepare is not a function". When I stringify the D1 database to inspect it I get the following object:
{
"alwaysPrimarySession": {
"fetcher": {},
"bookmarkOrConstraint": "first-primary"
},
"fetcher": {}
}
{
"alwaysPrimarySession": {
"fetcher": {},
"bookmarkOrConstraint": "first-primary"
},
"fetcher": {}
}
Can someone help me resolve the issue please ? Thanks,
1 replies