# Pg-typesafe – Strongly typed queries for PostgreSQL and Typ…

Throughout my career, I tried many tools to query PostgreSQL, and in the end, concluded that for what I do, the simplest is almost always the best: raw SQL queries. Until now, I typed the results manually and relied on tests to catch problems. While this is OK in e.g., GoLang, it is quite annoying…

- **Page:** https://magpie.gallery/i/pg-typesafe-strongly-typed-queries-for-postgresql-j3gu
- **Type:** Link to an idea elsewhere
- **Category:** AI & dev
- **Tags:** postgresql, typescript, sql, types, database

## Source

Web · n_e: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript

- **Original:** https://news.ycombinator.com/item?id=47050872

> Throughout my career, I tried many tools to query PostgreSQL, and in the end, concluded that for what I do, the simplest is almost always the best: raw SQL queries. Until now, I typed the results manually and relied on tests to catch problems. While this is OK in e.g., GoLang, it is quite annoying in TypeScript. First, because of the more powerful type system (it's easier to guess that updated_at is a date than it is to guess whether it's nullable or not), second, because of idiosyncrasies (INT4s are deserialised as JS numbers, but INT8s are deserialised as strings). So I wrote pg-typesafe, with the goal of it being the less burdensome: you call queries exactly the same way as you would call node-pg, and they are fully typed. It's very new, but I'm already using it in a large-ish project, where it found several bugs and footguns, and also allowed me to remove many manual type definitions. https://github.com/n-e/pg-typesafe

## GitHub projects

- https://github.com/n-e/pg-typesafe

## Rules for reuse

- Build your own version: don't copy another product's code, look, icons, colours or copy.
- The original belongs to its author; Magpie only links to it.
- The original content's copyright belongs to its creator. Magpie doesn't download or re-upload it; we only show the link and the official preview.
