quackatos
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

🦆 quackatos

NPM Test

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">

Setup

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

Goals

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.

Related Works

  • 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

Contributing

See CONTRIBUTING.md for details.

Package Sidebar

Install

npm i quackatos

Weekly Downloads

1

Version

1.8.0

License

MIT

Unpacked Size

80.2 kB

Total Files

6

Last publish

Collaborators

  • seveibar