-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a drizzle-schema package #3208
Comments
@arkemaz would you be interested in championing this? |
sure I can try |
@amosbastian here"s initial version without refine (the second argument) which passes insert test for mysql, pg and sqlite https://github.com/arekmaz/drizzle-orm/blob/effect-schema/drizzle-schema/src/effect-schema.ts edit: after some hours the insert tests are passing with refine implemented here"s the draft pr to |
@amosbastian all tests are passing, insert select, with/without refine, for each db, if you want you can copy that file to your project and test it, the only thing left is some package cleanup, and probably some time will pass before they accept the merge request, if they do at all |
Thanks for your hard work @arekmaz! I"ve finally got round to using it today, and it"s not 100% clear to me how we can use this to do something like
as we would with |
EDIT: it doesn"t work at the moment but in the end you should be able to do this: const insertUserSchema = createInsertSchema(usersTable);
const requestSchema = insertUserSchema.pick("name", "email"); as the output schemas will be just there is also the I"m a bit too busy to cleanup the package and request the merge at the moment, |
I created a new pull request drizzle-team/drizzle-orm#2665 - I"m new to commit signing let"s see if they accept it |
@datner it looks like the drizzle team did not even look at the pr, what do you think we should do with this? maybe try to merge it into |
deferring to @mikearnaldi 🙏🏻 |
I"d wait a bit longer and eventually evaluate if to merge in sql-drizzle |
I was just looking for this today. Currently I have to define drizzle schemas, my own domain schemas and then make conversions between the two. It is a bit cumbersome, and I wish this was already available. |
@danielo515 given 4 parsers: foo, bar, baz, and qux. Knowing that You can ping the PR there if you"re interested in pushing it in hehe |
I updated the types slightly to account for the different export type GetSchemaForType<TColumn extends Drizzle.Column> =
TColumn["dataType"] extends infer TDataType
? TColumn["columnType"] extends infer TColumnType
? TDataType extends "custom"
? Schema.Schema<any>
: TDataType extends "json"
? Schema.Schema<Json, Json>
: TColumn extends { enumValues: [string, ...string[]] }
? Drizzle.Equal<
TColumn["enumValues"],
[string, ...string[]]
> extends true
? Schema.Schema<string>
: Schema.Schema<TColumn["enumValues"][number]>
: TDataType extends "bigint"
? Schema.Schema<bigint, bigint>
: TDataType extends "number"
? TColumnType extends `PgBigInt${number}`
? Schema.Schema<bigint, number>
: Schema.Schema<number, number>
: TDataType extends "string"
? TColumnType extends "PgNumeric"
? Schema.Schema<number, string>
: TColumnType extends "PgUUID"
? Schema.Schema<string>
: TColumnType extends "PgDateString"
? Schema.Schema<Date, string>
: TColumnType extends "PgTimestampString"
? Schema.Schema<Date, string>
: Schema.Schema<string, string>
: TDataType extends "boolean"
? Schema.Schema<boolean>
: TDataType extends "date"
? Schema.Schema<Date>
: Schema.Schema<any>
: never
: never; |
What is the problem this feature would solve?
I"m slowly getting into Effect and am coming from a codebase where I use drizzle-zod, which is a plugin for Drizzle ORM that allows you to generate Zod schemas from Drizzle ORM schemas.
For example, you would be able to do something like the following:
What is the feature you are proposing to solve the problem?
It would be great to have an Effect equivalent (
drizzle-schema
) as described above.What alternatives have you considered?
I found this gist in this Discord thread, but it"s using an old version of Effect and I"m way too much on an Effect noob to even consider porting this to the latest version.
The text was updated successfully, but these errors were encountered: