Hello Can anyone guide me on how to connect workers with Cloudflare d1 and different environments Th

Hello
Can anyone guide me on how to connect workers with Cloudflare d1 and different environments
The connection is fine if i go with the default wrangler.toml configuration but the moment i go with this approach (Check code below) the db connection never happens at all

Approach i am trying to use

This is a staging environment

[env.staging]
d1_databases = [
{ binding = "DB", database_name = "<DATABASE_NAME_1>", database_id = "<UUID1>" },
]

This is a production environment

[env.production]
d1_databases = [
{ binding = "DB", database_name = "<DATABASE_NAME_2>", database_id = "<UUID2>" },
]


MY BINDING
export type Bindings = {
    DB: D1Database;
    ACCESS_TOKEN_SECRET: string;
};


my endpoint (Using hono js)
app.get('/', async (c) => {
    const res1 = await c.env.DB.prepare('SELECT * from testTable;').all();
    return c.json({ status: 'success', message: res1 });
});
Was this page helpful?