Hyperdrive with Drizzle missing connectionString

I am working on a project and trying to use Hyperdrive to connect to our DB on superbase via drizzle. I have the following:
import { drizzle } from "drizzle-orm/postgres-js";
import type { Hyperdrive } from "@cloudflare/workers-types";
import * as appSchema from "./schema.sql";
export interface Env {
HYPERDRIVE: Hyperdrive;
}

export function createDb(c: Env) {
const db = drizzle({
connection: {
url: c.HYPERDRIVE.connectionString,
prepare: false,
},
casing: "snake_case",
schema: appSchema,
});
return { db };
}
import { drizzle } from "drizzle-orm/postgres-js";
import type { Hyperdrive } from "@cloudflare/workers-types";
import * as appSchema from "./schema.sql";
export interface Env {
HYPERDRIVE: Hyperdrive;
}

export function createDb(c: Env) {
const db = drizzle({
connection: {
url: c.HYPERDRIVE.connectionString,
prepare: false,
},
casing: "snake_case",
schema: appSchema,
});
return { db };
}
But the connectionString is just undefined. I call this function via this:
import { createDb } from "$/drizzle";
export * as User from "./";
export const listAll = async (c) => {
const { db } = createDb(c);

const listUsers = await db.query.user.findMany();
return listUsers;
};
import { createDb } from "$/drizzle";
export * as User from "./";
export const listAll = async (c) => {
const { db } = createDb(c);

const listUsers = await db.query.user.findMany();
return listUsers;
};
From the hono route:
import type { AppRouteHandler } from "$/lib/types";
import { User } from "$/core/user";
import type { ListRoute } from "./tasks.routes";

export const list: AppRouteHandler<ListRoute> = async (c) => {
const result = await User.listAll(c);
return c.json(result);
};
import type { AppRouteHandler } from "$/lib/types";
import { User } from "$/core/user";
import type { ListRoute } from "./tasks.routes";

export const list: AppRouteHandler<ListRoute> = async (c) => {
const result = await User.listAll(c);
return c.json(result);
};
But the HYPERDRIVE.connectionString is undefined when I log it out. I validated that the binding is present in the console and when I run the hyperdrive tutorial am able to connect through it. I just dont understand where I am going wrong.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server