Hey, so I've been following the cloudflare's framework guide for qwik which demonstrates the usage of d1 bindings inside a qwik-app. What I am trying to achieve is just to insert data inside my production d1 so the online one and not local one in a cloudflare worker. I was creating the bindings on the cloudflare dashboard and setup everything correctly and carefuly followed the guideline here https://developers.cloudflare.com/pages/framework-guides/deploy-a-qwik-site/#use-bindings-in-your-qwik-application and it still can't recognize my DB somehow. Any approach by you guys, because I am frustrated as I can't access my D1 Database inside my cloudflare page (so the qwik app) for like several days already... -.-
import type { D1Database, D1PreparedStatement } from "@cloudflare/workers-types";
export const useUserRegistrationAction = routeAction$(async ({ email, username, password }, { fail, platform }) => {
const errors = []
if(!(new RegExp(/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/).test(email))) {
errors.push("Ungültige E-Mail-Adresse.")
}
const passwordLength = 8
if(password.length < passwordLength) {
errors.push(`Passwort muss mindestens ${passwordLength} Zeichen lang sein.`)
}
if(errors.length > 0) {
return fail(400, {
messages: errors
})
}
const passwordHash = await bcryptjs.hash(password, 10)
try{
// @ts-ignore
const { HEALTHYINSPECTION_DB } = (platform as { HEALTHYINSPECTION_DB: D1Database })
const preparedStatement: D1PreparedStatement = HEALTHYINSPECTION_DB
.prepare(`insert into account ('Email', 'Username', 'Password') values ('${email}', '${username}', '${passwordHash}')`)
const data = await preparedStatement.run()
return data.results[0].id
} catch (error) {
if(error instanceof Error) {
return fail(400, {
messages: [ error.message ]
})
}
}
}, zod$({
email: z.string(),
username: z.string(),
password: z.string()
}))
dashboard, so no worries about that (in the screenshot below this message you're currently reading there's being shown my d1 db binding for my worker...):