# adelsz/pgtyped

pgTyped - Typesafe SQL in TypeScript

Repository: https://github.com/adelsz/pgtyped
Canonical: https://ross.abutalabs.com/products/pgtyped
Homepage: https://pgtyped.dev
Language: TypeScript
License: MIT
License Family: permissive
Topics: postgres, typescript, query, generator, types, postgresql, sql, type-safety
Last push: 2026-08-26T15:52:30+00:00

## Health v2 (maintenance only)
Score: 74/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 99, release rhythm 28, longevity 100
- inputs: {"age_days": 2536, "days_push": 7, "days_rel": 537, "gap_med": 33, "n_releases_24m": 2}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 3276, forks 116 (observed 2026-08-28T04:07:53.450801+00:00)

## What it is
PgTyped is a TypeScript library that generates static types for raw SQL queries against a running PostgreSQL database. It parses queries from SQL or TS files and produces typed query functions without requiring schema definitions or acting as an ORM.

## Use cases
- generate TypeScript types for raw SQL queries
- use raw SQL with type safety in a Node.js app
- avoid writing an ORM schema mapping for Postgres
- prevent SQL injection when writing parameterized queries
- auto-generate query result and parameter interfaces from a live Postgres database
- write SQL in .sql files and get typed query functions

## When to choose
- you prefer writing raw SQL over query builders or ORMs
- you want compile-time type checking of query parameters and results
- your team uses PostgreSQL with TypeScript and wants minimal runtime overhead
- you want the live database schema to be the source of truth for types

## When to avoid
- you need an ORM with relations, migrations, and schema management
- you use a database other than PostgreSQL
- you don't want a running database connection during development for type generation
- you need runtime query building or dynamic SQL composition

## Facets
- artifact type: library
- maturity: active
- function: database, database-driver, type-system, developer-tools
- domain: databases, developer-tools, web-development, backend
- platform: cross-platform
- tags: sql, postgres, type-safety, query-generator, code-generation, raw-sql, esm, nodejs, typescript

## Member repositories
- adelsz/pgtyped (main) score 74

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:07:53.450801+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T18:43:22.023675+00:00, confidence not recorded.
  - readme: https://github.com/adelsz/pgtyped (fetched 2026-08-28T04:07:53.450801+00:00, sha 13b736c7793e)
  - homepage: https://pgtyped.dev (fetched 2026-08-29T09:36:24.426938+00:00, sha 062f3f53da91)
  - site_page: https://pgtyped.dev/docs (fetched 2026-08-29T09:36:24.435832+00:00, sha f50ec97f6489)
- Data as of 2026-08-30T08:39:29.467469+00:00.
