Registry / database / introspect-it

introspect-it

JSON →
library3.0.0jsnpmunverified

introspect-it is a CLI and library for converting PostgreSQL database schemas into TypeScript type definitions. Current stable version is 3.0.0. It focuses on simplicity and zero-configuration: given a Postgres connection string, it automatically infers tables and columns, generating TypeScript types with proper nullability and date handling. Inline enums are supported, but namespaces are not. It is inspired by schemats but simpler and Postgres-only. The library exports `inferSchema` and `inferTable` functions for programmatic use. Releases are infrequent but stable. Compared to alternatives like schemats or pg-to-ts, it requires no configuration files and produces concise output.

npm install introspect-it
INSTALL
IMPORT
SIG · INTROSPECT-IT
I
introspect-it
databasejavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inferSchema
import { inferSchema } from 'introspect-it'
import inferSchema from 'introspect-it'
Named export, not default.
inferTable
import { inferTable } from 'introspect-it'
import inferTable from 'introspect-it'
Named export.
introspect-it (CLI)
npx introspec-it postgresql://...
npx introspect-it postgresql://...
The package name is 'introspect-it' but CLI binary is 'introspec-it' (missing 't').

Programmatic usage of introspect-it: connect to a Postgres database and generate TypeScript types for the entire public schema.

import { inferSchema } from 'introspect-it' import { Client } from 'pg' async function main() { const connectionString = process.env.DATABASE_URL ?? 'postgresql://postgres@localhost:5432/mydb?currentSchema=public' const types = await inferSchema(connectionString) // types is a string containing TypeScript type definitions console.log(types) } main().catch(console.error)
Debug
Known issues
breakingIn version 3.0.0, the package was rewritten and the API changed from default export to named exports.
fix
Update imports to use named exports: import { inferSchema, inferTable } from 'introspect-it'
affects: <3.0.0
gotchaCLI binary name is 'introspec-it' (missing 't' after 'spec'), not 'introspect-it'.
fix
Use 'npx introspec-it' instead of 'npx introspect-it'.
affects: >=3.0.0
gotchaThe package only supports PostgreSQL; using it with MySQL or other databases will fail.
fix
Ensure your database is PostgreSQL before using introspect-it.
affects: >=3.0.0
gotchaConnection string must include the 'currentSchema' query parameter to specify which schema to introspect.
fix
Append '?currentSchema=public' (or your schema name) to the connection string.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'introspect-it'
Package not installed or using wrong import path
fix
Install the package: npm install introspect-it
error: relation "table_name" does not exist
Table name provided does not exist in the specified schema
fix
Check the table name and schema: ensure it exists and is spelled correctly, including the currentSchema parameter.
ERR_PNPM_NO_MATCHING_VERSION  No matching version found for introspect-it@3.0.0
Version mismatch or package not available in registry
fix
Run npm install introspect-it@latest to get the latest version.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
pgrequiredUsed to connect to PostgreSQL and query schema information
Agent activity
9 hits · last 30 days
node
8
Resources
introspect-it — npm install introspect-it · libregistry