hero

Reverse Engineer PostgreSQL

Get database structure as a detailed JavaScript or TypeScript object.

Get Started →

Enhanced Arrays

Collections supports all array methods such as map, reduce, forEach() as well as direct access methods such as get.

TypeScript

Written in TypeScript. In addition to support JavaScript, all typings are available in TypeScript.

Documented

All classes, class attributes and methods are documented and available via documentation web site.

const columnNames = db.get("contact").columns.map((c) => c.name); // Column names of `public.contact` table.

# Reverse Engineer a PostgreSQL Database

Open source pg-structure reverse engineers PostgreSQL database and lets you easily code, analyze, operate on PostgreSQL database structure by providing details about DB, Schema, Table, Column, ForeignKey, Relation, Index, Type. etc.

import pgStructure from "pg-structure";

async function demo() {
  // pg-structure may read client config from process.env. Use environment variables for sensitive information such as passwords.
  const db = await pgStructure({ database: "db", user: "u", password: "pass" }, { includeSchemas: ["public"] });

  const accountTable = db.get("account"); // TypeScript: db.get("account") as Entity
  const table = db.tables.get("contact");
  const columnNames = table.columns.map((c) => c.name);
  const columnTypeName = table.columns.get("options").type.name;
  const indexColumnNames = table.indexes.get("ix_mail").columns;
  const relatedTables = table.hasManyTables;
}

# Sponsors

JetBrains Logo EMS SQL Manager Logo Wallaby.js Logo Codeweavers Logo