hero

Reverse engineer PostgreSQL database as a detailed JS 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

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() {
  const db = await pgStructure({ database: "db", user: "u", password: "pass" }, { includeSchemas: ["public"] });

  const table = db.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;
}

# Changes

If you upgrade, please see v5 beraking changes.