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/ |
|
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.
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;
}