frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript

https://github.com/n-e/pg-typesafe
26•n_e•5h ago
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.

Comments

barishnamazov•1h ago
How is this different than kysely + kysely-codegen (or hand-made types)?
ZiiS•36m ago
It only changes the types; not the code.
n_e•30m ago
Kysely is a query builder: you build queries by calling javascript functions, while with pg-typesafe you write SQL directly.

I've used kysely before creating pg-typesafe, and came to the conclusion that writing SQL directly is more convenient.

A query builder works well for simple cases (db.selectFrom("t").where("id","=","1") looks a lot like the equivalent SQL), however, for more complicated queries it all falls apart. I often had to look at the docs to find how to translate some predicate from SQL to the required idiom. Also, I don't think kysely can automatically infer the return type of PostgreSQL functions, while pg-typed does (it asks PostgreSQL for it).

semiquaver•29m ago
How is this different from sqlc with sqlc-gen-typescript?
n_e•16m ago
I didn't look too much into sqlc-gen-typescript because the project looks abandoned (no commits in 2 years, many open PRs).

Regarding sqlc in general, it is focused on having the SQL queries in .sql files, while pg-typed is focused on having the queries inline (though I plan to add .sql file support). I like the latter approach better, as for small queries used in only one place, it is a little cumbersome to add them to a different file and find a name for them.

1-more•27m ago
If you're into Haskell prior art, there's postgresql-typed https://hackage.haskell.org/package/postgresql-typed-0.6.2.5... where you write queries, it safely(?) puts in your variables, and you automatically get back typed values.
dbbk•2m ago
Just use Drizzle

Show HN: AsteroidOS 2.0 – Nobody asked, we shipped anyway

https://asteroidos.org/news/2-0-release/index.html
227•moWerk•4h ago•27 comments

Show HN: I wrote a technical history book on Lisp

https://berksoft.ca/gol/
140•cdegroot•7h ago•38 comments

Show HN: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript

https://github.com/n-e/pg-typesafe
26•n_e•5h ago•7 comments

Show HN: Auto-Layouting ASCII Diagrams

https://github.com/switz/box-of-rain
6•switz•3d ago•2 comments

Show HN: I built the Million Dollar Homepage for agents

https://onemillionpixels.ai/
6•talboren•9h ago•2 comments

Show HN: I'm launching a LPFM radio station

https://www.kpbj.fm/
41•solomonb•3h ago•29 comments

Show HN: I taught LLMs to play Magic: The Gathering against each other

https://mage-bench.com/
84•GregorStocks•7h ago•65 comments

Show HN: Writing a C++20M:N Scheduler from Scratch (EBR, Work-Stealing)

https://github.com/lixiasky-back/tiny_coro-build_your_own_MN_scheduler
2•lixiasky•44m ago•0 comments

Show HN: 6cy – Experimental streaming archive format with per-block codecs

https://github.com/byte271/6cy
26•yihac1•6h ago•8 comments

Show HN: Continue – Source-controlled AI checks, enforceable in CI

https://docs.continue.dev
36•sestinj•6h ago•7 comments

Show HN: Glitchy camera – a circuit-bent camera simulator in the browser

https://glitchycam.com
160•elayabharath•1d ago•21 comments

Show HN: KrillClaw – 49KB AI agent runtime in Zig for $3 microcontrollers

https://github.com/krillclaw/KrillClaw
4•myonatan•2h ago•2 comments

Show HN: Distillate – Zotero papers → reMarkable highlights → Obsidian notes

https://distillate.dev
3•rhl•2h ago•3 comments

Show HN: OpenBoot – 2 commands to replace a 3-hour Mac setup ritual

https://github.com/openbootdotdev/openboot
9•superjam2026•6h ago•3 comments

Show HN: Cycast – High-performance radio streaming server written in Python

https://github.com/LukeB42/Cycast
18•LukeB42•7h ago•2 comments

Show HN: Jemini – Gemini for the Epstein Files

https://jmail.world/jemini
457•dvrp•1d ago•90 comments

Show HN: Scanned 1927-1945 Daily USFS Work Diary

https://forestrydiary.com/
112•dogline•23h ago•27 comments

Show HN: Relay – I built a modern web-based IRC/Discord replacement

https://relay.moltic.dev/
8•redmageinc•8h ago•0 comments

Show HN: Wildex – Pokémon Go for real wildlife

https://apps.apple.com/us/app/wildex-identify-plants-animals/id6748092158
99•AnujNayyar•1d ago•69 comments

Show HN: NBA-API-ts – Zero-dep TypeScript client for 138 NBA stats endpoints

https://github.com/gek0z/nba-api-ts
2•gek0z•3h ago•1 comments

Show HN: I curated 130 US PDF forms and made them fillable in browser

https://simplepdf.com/forms
7•nip•4h ago•0 comments

Show HN: Maths, CS and AI Compendium

https://github.com/HenryNdubuaku/maths-cs-ai-compendium
85•HenryNdubuaku•1d ago•19 comments

Show HN: Free alternative to Wispr Flow, Superwhisper, and Monologue

https://github.com/zachlatta/freeflow
259•zachlatta•1d ago•123 comments

Show HN: Lap – Fast photo browsing for libraries (Rust and Tauri)

https://github.com/julyx10/lap
2•julyxx•5h ago•0 comments

Show HN: 2D Coulomb Gas Simulator

https://simonhalvdansson.github.io/2D-Coulomb-Gas-Tools/index_gpu.html
39•swesnow•1d ago•9 comments

Show HN: Simple org-mode web adapter

https://github.com/SpaceTurth/Org-Web-Adapter
61•turth•1d ago•7 comments

Show HN: Self-Hosted Task Scheduling System (Back End and UI and Python SDK)

https://github.com/Ghiles1010/Cratos-UI
2•rilesthefirst•6h ago•0 comments

Show HN: Listen to sounds around the world and guess the location

https://placethesound.vikborges.com
2•bit_nomad•6h ago•0 comments

Show HN: PIrateRF – Turn a $20 Raspberry Pi Zero into a 12-mode RF transmitter

https://github.com/psyb0t/piraterf
7•metadescription•9h ago•3 comments

Show HN: Trained YOLOX from scratch to avoid Ultralytics (aircraft detection)

https://austinsnerdythings.com/2026/02/13/training-yolox-aircraft-detection-mit-license/
2•auspiv•6h ago•0 comments