PostgreSQL pg-structure.com

Extract the structure of a Postgres database into JavaScript  ↦

When your database is the source of truth, it’s often useful to inspect that truth and reuse it elsewhere in your application.

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

Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00