knex-types

Generate TypeScript definitions (types) from a PostgreSQL database schema.

MIT License

Downloads
19.2K
Stars
63
Committers
5

Bot releases are visible (Hide)

knex-types - v0.5.0 Latest Release

Published by koistya almost 2 years ago

  • feat: Add support for int2 extension integer type (#26) — @cskeppstedt
  • chore: Upgrade dependencies (#27) — @koistya
knex-types -

Published by koistya over 2 years ago

  • feat: Generate Tables type (#14) — @d7ark
knex-types - v0.3.2

Published by koistya almost 3 years ago

  • Escape generated property names containing spaces or special characters (#11) — @bhenderson
knex-types - v0.3.1

Published by koistya about 3 years ago

  • Add options.suffix option (#7) — @bhenderson
knex-types - v0.3.0

Published by koistya about 3 years ago

  • Add schema and exclude options (#2) — @erlinghaugstad
updateSchema(db, {
  schema: ["public", "log"], // defaults to "public"
  exclude: ["migrate", "migrate_lock"], // defaults to []
}
knex-types -

Published by koistya over 3 years ago

Allow to add a custom prefix; improve the supported type coverage.

updateTypes({
  output: `./types.ts`,
  // Inject a custom import at the top of the generated file
  prefix: `import { PostgresInterval } from "postgres-interval";`
});

Drop generation of EntityRecord types, use Knex.DbRecord<Entity> instead.

knex-types -

Published by koistya over 3 years ago

Add citext[] db type, saving it as string[].

knex-types -

Published by koistya over 3 years ago

An utility module for Knex.js that generates TypeScript definitions (types) from a PostgreSQL database schema.

$ npm install knex
$ npm install knex-types --dev

Usage Example

const { knex } = require("knex");
const { updateTypes } = require("knex-types");

const db = knex(require("./knexfile"));

updateTypes(db, { output: "./types.ts" }).catch((err) => {
  console.error(err);
  process.exit(1);
});

Find an example of generated types in ./main.test.ts.