# pg-structure

> Reverse engineer PostgreSQL database as a detailed JS Object.

Latest version **7.15.3** (published 2024-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-structure
pnpm add pg-structure
yarn add pg-structure
bun add pg-structure
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.15.3 |
| Published | 2024-05-16 |
| First published | 2014-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14.0.0 |
| Dependencies | 9 |
| Unpacked size | 520 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 360 |
| Author | Özüm Eldoğan |
| Maintainers | ozum |
| Keywords | postgresql, reverse engineer, pg, structure, database, object |

## Links

- npm: https://www.npmjs.com/package/pg-structure
- Repository: https://github.com/ozum/pg-structure
- Homepage: https://www.pg-structure.com
- Issues: https://github.com/ozum/pg-structure/issues
- npm.io page: https://npm.io/package/pg-structure

## Dependencies (9)

- [pg](https://npm.io/package/pg.md) ^8.0.3
- [json5](https://npm.io/package/json5.md) ^2.1.3
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0
- [inflection](https://npm.io/package/inflection.md) ^1.12.0
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [fast-memoize](https://npm.io/package/fast-memoize.md) ^2.5.2
- [indexable-array](https://npm.io/package/indexable-array.md) ^0.7.4
- [pg-connection-string](https://npm.io/package/pg-connection-string.md) ^2.2.1
- [@typescript-plus/fast-memoize-decorator](https://npm.io/package/@typescript-plus/fast-memoize-decorator.md) ^0.1.0

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 7.15.3 (latest) — 2024-05-16
- 7.15.2 — 2024-02-12
- 7.15.1 — 2024-02-12
- 7.15.0 — 2023-05-29
- 7.14.0 — 2023-04-13
- 7.13.1 — 2022-10-11
- 7.13.0 — 2021-12-07
- 7.12.1 — 2021-03-06
- 7.12.0 — 2021-03-01
- 7.11.1 — 2021-03-01
- 7.11.0 — 2021-02-28
- 7.10.0 — 2021-02-28
- 7.9.0 — 2021-02-27
- 7.8.0 — 2021-02-27
- 7.7.1 — 2021-02-24
- … 150 more at https://npm.io/package/pg-structure/versions

## README

# pg-structure

Reverse engineer PostgreSQL database as a detailed JS Object.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Home Page](#home-page)
- [Installation](#installation)
- [Synopsis](#synopsis)
- [Details](#details)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Home Page

Please see [pg-structure.com](https://www.pg-structure.com) for details.

# Installation

`$ npm install pg-structure`

# Synopsis

```ts
import pgStructure from "pg-structure";

async function demo() {
  // Prefer to use environment variables or ".env" file for the credentials. See the ".env.example" file.
  const db = await pgStructure({ host: "host", 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;
}
```

# Details

`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 and others.

---
_Source: https://npm.io/package/pg-structure · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
