Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
home heroImage heroText tagline actionText actionLink features footer
true
/images/hero.png
Reverse Engineer PostgreSQL
Get database structure as a detailed JavaScript or TypeScript object.
Get Started →
/nav.01.guide/
title details
Enhanced Arrays
Collections supports all array methods such as map, reduce, forEach() as well as direct access methods such as get.
title details
TypeScript
Written in TypeScript. In addition to support JavaScript, all typings are available in TypeScript.
title details
Documented
All classes, class attributes and methods are documented and available via documentation web site.
MIT Licensed | Copyright © 2019-present Özüm Eldoğan
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