Knex Types Versions Save

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

v0.5.0

1 year ago
  • feat: Add support for int2 extension integer type (#26) — @cskeppstedt
  • chore: Upgrade dependencies (#27) — @koistya

v0.4.0

2 years ago
  • feat: Generate Tables type (#14) — @d7ark

v0.3.2

2 years ago
  • Escape generated property names containing spaces or special characters (#11) — @bhenderson

v0.3.1

2 years ago
  • Add options.suffix option (#7) — @bhenderson

v0.3.0

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

v0.2.0

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.

v0.1.4

3 years ago

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

v0.1.3

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.