Quackatos is an extremely well-typed query builder for Postgres, built on top of the excellent Zapatos library.
For example:
import q from "quackatos"
import { Pool } from "pg"
const pool = new Pool()
const filmAndActor = await q("film")
.leftJoin("film_actor", "film.film_id", "film_actor.film_id")
.leftJoin("actor", "actor.actor_id", "film_actor.actor_id")
.select("actor.first_name", "film.*")
.limit(1)
.run(pool)
// typeof filmAndActor ===
// film.Selectable &
// Pick<NullPartial<actor.Selectable>, "first_name">
First, you'll have to set up Zapatos (Quackatos relies on Zapatos for type generation and helper functions).
Then:
yarn add quackatos
or npm install quackatos
If it looks like a duck, swims like a duck, and quacks like a duck, then it's probably a duck.
Quackatos has three main goals:
- Query results should be strongly typed to the fullest extent possible
- Any code without type errors should generate a valid query
- It should be immediately obvious what Postgres query will be generated for any given code
Quackatos does not intend to be a drop-in replacement for Knex, though it shares much of the same syntax.
- Knex: a weakly-typed query builder for many different database engines
- Prisma: a strongly-typed ORM for many different database engines
- Zapatos: a type generation and query helper library for Postgres
See CONTRIBUTING.md for details.