Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kristiandupont/kanel

Generate Typescript types from Postgres
https://github.com/kristiandupont/kanel

Last synced: 10 days ago
JSON representation

Generate Typescript types from Postgres

Awesome Lists containing this project

README

        

![Kanel Logo](./logo-bright.png#gh-light-mode-only)
![Kanel Logo](./logo-dark.png#gh-dark-mode-only)

Generate Typescript types from a live Postgres database.

This is for people who don't like ORM's but who do like intellisense and type checking for their database access code.

See the documentation [here](https://kristiandupont.github.io/kanel)

Introduction to the idea is outlined [here](https://medium.com/@kristiandupont/generating-typescript-types-from-postgres-48661868ef84).

## Usage

Install with:

```bash
$ npm i -D kanel
```

To run, make sure you are in a folder that has a `.kanelrc.js` configuration file and that your database is running, and type:

```bash
$ npx kanel
```

## Programmatical usage

Example of running generation from code:

```typescript
import { processDatabase } from "kanel";
import config from "./kanelrc";

async function run() {
await processDatabase(config);
}

run();
```

## Example

To see an example of the result, check out the [/example](example) folder. It uses the [Sample Database](https://www.postgresqltutorial.com/postgresql-sample-database/) from www.postgresqltutorial.com.

---

If you want to learn about how I use this together with [tRPC](https://trpc.io/) to create end-to-end type safety with PostgreSQL as the source of truth, check out my course on Newline:



---

---

## Contributors



Made with [contrib.rocks](https://contrib.rocks).