Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/barelyhuman/knex-types

Auto Generate Types for your database schema from your knex instance.
https://github.com/barelyhuman/knex-types

autogenerate database generate knex models types typescript

Last synced: 2 days ago
JSON representation

Auto Generate Types for your database schema from your knex instance.

Awesome Lists containing this project

README

        

# @barelyhuman/knex-types

> Generate Model types from Knex

- [@barelyhuman/knex-types](#barelyhumanknex-types)
- [Schema Support](#schema-support)
- [Usage](#usage)
- [License](#license)

## Schema Support

While the below checklist mentions **Partial**, most of what the library can generate should be usable. It says partial because things like `enum` and other constraints that can be used to generate better types and models for knex are still not done.

- [x] Sqlite
- [ ] Postgres (Partial)
- [ ] MSSQL (Partial)
- [ ] Oracle (Partial)

## Usage

```js
// in CJS
const { generateTypes } = require("@barelyhuman/knex-types");
const knexInstance = knex(config);

generateTypes(knexInstance, {
output: "./types.d.ts",
}).then((d) => {
// Done
});
```

```js
// in ESM
import { generateTypes } from "@barelyhuman/knex-types";
const knexInstance = knex(config);
await generateTypes(knexInstance, {
output: "./types.d.ts",
});
```

## License

[MIT](/LICENSE)