You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Give long-time slonik users a way to migrate to the value of runtime validation without having to stay pinned on an older version of Slonik. I have working code in production that I'd be glad to share in a PR.
Desired Behavior
Allow non-Zod types for queries (like we've historically had)
interface DataTest { foo: string, bar: string; };
const qry = sql.legacy<DataTest>`SELECT * FROM data_tests WHERE ${whereClause}`;
const results = await db.many<DataTest>(sql.unsafe`SELECT * FROM data_tests WHERE id = ${inserted.id}`);
I went with this approach bc it still leaves "marker" names in place to help us find where to go back and fix up properly (the things to search for being sql.legacy and sql.unsafe)
This did require some mass-renaming in the codebase ( sql' => sql.unsafe' and sql<' => sql.legacy' )
Motivation
It appears that the breaking changes in v33 and beyond are mostly Typescript related. I put together some of the types below to give us backward compatibility in our codebase as migrating our entire data access layer to Zod models was not something we could do in one shot. We are migrating, as runtime validation is a huge need, but its just not an overnight thing.
Implementation
I am currently using the following types in a ./db/index.ts file that all of my consuming code imports from. I re-export the slonik types from here (overridden) and then make sure none of the consuming code is importing slonik directly.
Agreed, I'm running into this now as well. Being able to gradually migrate from generics to Zod validation would make upgrading significantly easier and allow us to have smaller, testable changesets
Give long-time slonik users a way to migrate to the value of runtime validation without having to stay pinned on an older version of Slonik. I have working code in production that I'd be glad to share in a PR.
Desired Behavior
Allow non-Zod types for queries (like we've historically had)
Allow non-Zod types for query helper functions (like we've historically had):
sql.legacy
andsql.unsafe
)sql' => sql.unsafe'
andsql<' => sql.legacy'
)Motivation
It appears that the breaking changes in v33 and beyond are mostly Typescript related. I put together some of the types below to give us backward compatibility in our codebase as migrating our entire data access layer to Zod models was not something we could do in one shot. We are migrating, as runtime validation is a huge need, but its just not an overnight thing.
Implementation
I am currently using the following types in a
./db/index.ts
file that all of my consuming code imports from. I re-export the slonik types from here (overridden) and then make sure none of the consuming code is importing slonik directly.I also have unit tests that I'd be willing to contribute.
The text was updated successfully, but these errors were encountered: