bug: Client component - Drizzle schema - env error
john093e opened this issue · comments
Provide environment information
turbo dev
Describe the bug
inside a client component:
import { schema } from "@acme/db"
Seems to load the whole index.ts and so return env error as env can't be use in client.
Link to reproduction
To reproduce
import {schema} from "@acme/db"
schema.post.status.enumValues.map((status) => ({
// do somthing with it
Additional information
No response
Why do you need your schema in client components?
Maybe I don't use it well :/
In order to create an option list for example in a table, for filtering, ordering, or to build form to create or update.
For example a "Post" table with a column "status" set to an enumerate value like "archived | editing | published", i would use like this
import {schema} from "@acme/db"
<select>
{schema.post.status.enumValues.map((status) => (
<option>{status}</option>
))}
</select>
You can define the status-enum in @acme/validators
then re-export it from there.
You can also use drizzle-zod there for getting the enum values https://orm.drizzle.team/docs/zod.
@andrewdoro , I still think you can't use schemas that came from drizzle-zod in client components. I tried it recently myself.
See: #966
@dBianchii this was introduced by this andrewdoro@5db63fb
@juliusmarminge saw your PR, was thinking about a simpler solution
#990
update: nvm you actually opened the same PR