Skip to content
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

Make Slonik runtime validation non-Zod specific #514

Closed
gajus opened this issue Oct 5, 2023 · 6 comments
Closed

Make Slonik runtime validation non-Zod specific #514

gajus opened this issue Oct 5, 2023 · 6 comments

Comments

@gajus
Copy link
Owner

gajus commented Oct 5, 2023

Desired Behavior

I should be able to initiate sql tag and pool with types that override the base Zod types.

I initially thought this would be a huge lift, but after doing some refactoring realized that we really need to override just two types: ZodTypeAny and z.infer.

Therefore, Slonik could be made non-Zod specific with an API similar to:

import { createSlonik, type SlonikDatabasePool } from 'slonik';
import { type ZodTypeAny, type z } from 'zod';

export const {
  createPool,
  createSql,
} = createSlonik<z.infer, ZodTypeAny>();

export type DatabasePool = SlonikDatabasePool<z.infer, ZodTypeAny>;

(This is just a rough idea, not a suggestion for the API.)

Then the consumer of Slonik would create a file in their project that sets up Slonik and consume exports from that file throughout their project, rather than directly importing from Slonik (that's already the recommended pattern anyway).

Motivation

Not everyone uses Zod.

Implementation

N/A

@mmkal
Copy link
Contributor

mmkal commented Oct 5, 2023

This is roughly what I was going for in #371

@gajus
Copy link
Owner Author

gajus commented Oct 5, 2023

This is roughly what I was going for in #371

Blocked some time this evening to refresh memory.

Sorry that it got pushed aside; at the time I was overwhelmed with feedback.

@CodePsy-2001
Copy link

Wouldn't a middleware approach be better? It seems odd that you have to install the zod library to not use zod.

@jareware
Copy link

FWIW, there's plenty of us out there who love Slonik, but would also love to be able to use something else than Zod. Not that there's anything wrong with Zod itself, but we have a non-trivial amount of code already using io-ts, and it'd be a bit silly to have both around.

@GianaS
Copy link

GianaS commented Jan 26, 2024

@gajus Is there any intention to see this through? My team is finding the Zod requirement to be very clunky with v37 since we already heavily rely on runtypes. If not, we unforunately may have to consider a Slonik alternative 😞

@gajus
Copy link
Owner Author

gajus commented Jan 26, 2024

Realistically, not within any reasonable timeframe. It is something I would want to support, but it is big lift to do it properly, and I have no commercial reason to undertake it.

@gajus gajus closed this as completed Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants