DT
Drizzle Team•14mo ago
T O

Error: this.client.prepare is not a function

I am trying to build a project using Bun, Hono and Drizzle. When i am starting the project with this piece of code :
import { Hono } from 'hono'
import postgres from 'postgres';
import {drizzle} from 'drizzle-orm/d1';
import {migrate} from 'drizzle-orm/d1/migrator';

const sql = postgres(process.env.DATABASE_URL, { max: 1 });
const db = drizzle(sql);

await migrate(db, { migrationsFolder: "drizzle" });

const app = new Hono();
app.get('/', (c) => c.text('Hello Hono!'));

export default app;
import { Hono } from 'hono'
import postgres from 'postgres';
import {drizzle} from 'drizzle-orm/d1';
import {migrate} from 'drizzle-orm/d1/migrator';

const sql = postgres(process.env.DATABASE_URL, { max: 1 });
const db = drizzle(sql);

await migrate(db, { migrationsFolder: "drizzle" });

const app = new Hono();
app.get('/', (c) => c.text('Hello Hono!'));

export default app;
I am encountering this error :
DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
': this.client.prepare is not a function. (In 'this.client.prepare(query.sql)', 'this.client.prepare' is undefined)
DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
': this.client.prepare is not a function. (In 'this.client.prepare(query.sql)', 'this.client.prepare' is undefined)
I've run the drizzle-kit generate:pg command before and I've checked my connection string many times Thank you for your help 🙂
1 Reply
kareem7484
kareem7484•12mo ago
I had the same issue and it was because I did not use the right import for drizzle. Make sure that the import "import {drizzle} from 'drizzle-orm/d1'"are for the right db. In this case, Cloudflare D1 is for sql-lite and not postgres.
Want results from more Discord servers?
Add your server