Env is not defined

I am trying to build a simple application with D1. When I try env.DB.get I get this error env.DB.get is not a function I am not sure why I am getting this error?

const { results } = await env.DB.get('SELECT * FROM Posts').all()

return new Response(results);

What am I doing wrong? when I use .perpare I get Posts is not a table Even though I have created it through the workers Dashboard

Are you passing env to the function?