slonik
zod
Our great sponsors
slonik | zod | |
---|---|---|
71 | 280 | |
4,328 | 29,771 | |
- | - | |
9.2 | 8.7 | |
1 day ago | 7 days ago | |
TypeScript | TypeScript | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
slonik
-
Drizzle is just as unready for prime-time as Prisma, what else is there?
I'd push you to consider using postgres, slonik or similar for database queries. With these libraries, you just write SQL, but they perform input sanitization for you. So you can safely write:
-
PostgresJs: The Fastest full featured PostgreSQL client for Node.js and Deno
You can already use postgres with Slonik.
https://github.com/gajus/slonik#user-content-slonik-how-are-...
It is not going to be the default because it is way slower.
https://github.com/gajus/slonik/actions/runs/6616647651
Test node_version:18 test_only:postgres-integration is taking 3 minutes.
Test node_version:18 test_only:pg-integration is taking 38 seconds.
-
Integrating Slonik with Express.js
For those uninitiated, Slonik is a battle-tested SQL query building and execution library for Node.js. Its primary goal is to allow you to write and compose SQL queries in a safe and convenient way. Now, let's see how it pairs with Express.js.
-
We use TypeScript not based on preference, but because we want to make money
I've found libraries like Zod useful when interacting with external data sources like a database. Slonik[1] uses Zod to define the types expected from a SQL query and then performs runtime validation on the data to ensure that the query is yielding the expected type.
I don't think it's necessary to use Zod/runtime validation everywhere, but it's a nice tool to have on hand.
-
Is ORM still an anti-pattern?
Demonstrate how easily and accidentally one can make an SQL injection with these:
-
The Epic Stack by Kent C. Dodds
Have you tried Slonik (https://github.com/gajus/slonik)? It won't generate types from queries automatically, but it encourages writing SQL vs. a query builder and allows type annotations of queries with Zod. Query results are validated at runtime to ensure the queries are typed correctly.
- TIL that you don’t shouldn’t be generating TypeScript declarations for a distributable library
-
All JavaScript and TypeScript features of the last 3 years explained
Definitely a lot of misconceptions around how this would work. Just check out something like slonik, https://github.com/gajus/slonik, which is an excellent implementation.
The example you gave actually isn't valid, because what you're doing is generating SQL dynamically, and that doesn't work the way prepared statements work. That is, you can't have a prepared statement like "select foo from bar where zed = ? order by ? asc", because with prepared statements the question marks can only substitute for VALUES, not schema names. So if you wanted to do something like that it slonik, it would fail. With slonik you CAN do dynamic SQL, that is guaranteed to be safe and checked at compile time with TypeScript, because you can nest SQL tagged template. That is you can do this:
const colToSortBy = useFoo ? sql`foo` : sql`bar`;
-
Working with TypeORM 0.3x with Nestjs - I wasn't aware so many people were facing issues with it
In general with ORMs, you will face a problem in one way or another. I ended up simply using https://github.com/gajus/slonik and https://github.com/amacneil/dbmate for migrations. My life is way much better since then.
zod
-
Eloquent JavaScript 4th edition (2024)
It is (or should be) common practice to parse/validate any external data you depend on. You should be doing this for Javascript too. I find that the library https://zod.dev/ is quite helpful for this
-
How to build a blog with Astro
Astro uses Zod, a Typescript-first schema validation library, to type-check the collections' schemas. It helps validate data types when using collections inside UI components.
-
Translating zod errors with next-intl
When starting a new project with Next.js these days, next-intl and zod are my go to libraries for internationalization and schema validation, respectively. Of course, when using zod for client-facing validations I would like to translate potential error messages. The package zod-i18n can be used to achieve this for i18next, a popular alternative internationalization library. This means that by using this library as starting point one can quickly achieve zod translation with next-intl.
-
Htmx vs. React: A Complete Comparison – Semaphore
That is certainly one interpretation, but even then within most compile-time but not runtime-checked languages you can usually perform runtime checks. For example I've used Zod (https://zod.dev/) quite a bit in typescript to do runtime typechecks at the boundaries.
-
Creating Dynamic Forms with React, Typescript, React Hook Form and Zod
Learn more about Zod in the official documentation
-
Leveraging WordPress as a Headless CMS for Your Astro Website: A Comprehensive Guide
Zod for robust type validation, enhancing code reliability.
-
I write HTTP services in Go after 13 years (Mat Ryer, 2024)
So far I like the commonly used approach in the Typescript community best:
1. Create your Schema using https://zod.dev or https://github.com/sinclairzx81/typebox
2. Generate your Types from the schema. It's very simple to create partial or composite types, e.g. UpdateModel, InsertModels, Arrays of them, etc.
3. Most modern Frameworks have first class support for validation, like is a great example Fastify (with typebox). Just reuse your schema definition.
That is very easy, obvious and effective.
-
[React JS] I don't know a better way to handle Forms in React
But now, all those difficulties are gone since I found React Hook Form and zod.
- Squeezing more performance out of your Nextjs App
-
How to build a WhatsApp AI assistant
Zod, a popular typescript schema validation library that will let us define the shape of the payload sent to our background job.
What are some alternatives?
class-validator - Decorator-based property validation for classes.
joi - The most powerful data validation library for JS [Moved to: https://github.com/sideway/joi]
Yup - Dead simple Object schema validation
typebox - Json Schema Type Builder with Static Type Resolution for TypeScript
ajv - The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
io-ts - Runtime type system for IO decoding/encoding
Superstruct - A simple and composable way to validate data in JavaScript (and TypeScript).
class-transformer - Decorator-based transformation, serialization, and deserialization between objects and classes.
runtypes - Runtime validation for static types
react-hook-form - 📋 React Hooks for form state management and validation (Web + React Native)
TypeScript - TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Knex - A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.