Add VineJS validation (via drizzle-vine package)#5466
Open
ChronicStone wants to merge 11 commits intodrizzle-team:mainfrom
Open
Add VineJS validation (via drizzle-vine package)#5466ChronicStone wants to merge 11 commits intodrizzle-team:mainfrom
drizzle-vine package)#5466ChronicStone wants to merge 11 commits intodrizzle-team:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new package:
drizzle-vine. It works just like the other validator packages (drizzle-zod,drizzle-valibot, etc.) but targets VineJS.The main motivation is AdonisJS. Adonis ships with VineJS as its built-in validator, so anyone building an Adonis app with Drizzle today has to either maintain two separate schema definitions or bolt on a different validation library. This package closes that gap and lets you derive your VineJS schemas directly from your Drizzle tables.
Supported dialects: PostgreSQL, MySQL, SQLite, SingleStore.
Example
Known limitations
VineJS does not have native support for
bigintor Node.jsBuffervalues. Columns of those types fall back tovine.any()at both the runtime and type level. If you need validation on those columns you can supply a custom schema through the refine option.A note on TypeScript performance
VineJS's type system requires four explicit type parameters on
VineObject<Properties, Input, Output, CamelCaseOutput>compared to one for Zod, and its modifier chain adds overhead per column.As a result
drizzle-vinecurrently sits around 600k type instantiations versus ~80k fordrizzle-zodon a typical schema. That gap is mostly structural and inherent to how VineJS exposes its types rather than something fixable with straightforward tuning. The implementation already avoids the most expensive patterns (no per-column modifier chain inference, single-pass output type computation via arithmetic unions), so the overhead that remains is about as low as I could get it for now.There is probably still room for improvement as VineJS's type architecture evolves, but it works fine in practice and compile times stay reasonable.