t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.28k stars 352 forks source link

bug: Client component - Drizzle schema - env error #988

Closed john093e closed 1 month ago

john093e commented 2 months ago

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

dBianchii commented 2 months ago

Why do you need your schema in client components?

john093e commented 2 months ago

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>
andrewdoro commented 2 months ago

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.

dBianchii commented 2 months ago

@andrewdoro , I still think you can't use schemas that came from drizzle-zod in client components. I tried it recently myself.

See: https://github.com/t3-oss/create-t3-turbo/discussions/966

andrewdoro commented 2 months ago

@dBianchii this was introduced by this https://github.com/andrewdoro/create-t3-turbo/commit/5db63fbaf5fbfebd1209e89bf345aa1d018c540e ~~@juliusmarminge saw your PR, was thinking about a simpler solution https://github.com/t3-oss/create-t3-turbo/pull/990~~ update: nvm you actually opened the same PR