# pgsqlinfo

> TypeScript library to work with information schema of PostgreSQL

Latest version **1.4.6** (published 2022-03-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install pgsqlinfo
pnpm add pgsqlinfo
yarn add pgsqlinfo
bun add pgsqlinfo
```

## 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 | 1.4.6 |
| Published | 2022-03-20 |
| First published | 2022-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 30.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Haci Murat Yaman |
| Maintainers | muratyaman |
| Keywords | postgresql, information, schema, typescript, types |

## Links

- npm: https://www.npmjs.com/package/pgsqlinfo
- Repository: https://github.com/muratyaman/pgsqlinfo
- Homepage: https://github.com/muratyaman/pgsqlinfo#readme
- Issues: https://github.com/muratyaman/pgsqlinfo/issues
- npm.io page: https://npm.io/package/pgsqlinfo

## Dependencies (1)

- [pg](https://npm.io/package/pg.md) ^8.7.3

## 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

- 1.4.6 (latest) — 2022-03-20
- 1.4.5 — 2022-03-20
- 1.4.4 — 2022-03-20
- 1.4.3 — 2022-03-20
- 1.4.2 — 2022-03-20
- 1.4.1 — 2022-03-20
- 1.4.0 — 2022-03-20
- 1.3.0 — 2022-03-19
- 1.2.0 — 2022-03-19
- 1.1.2 — 2022-03-18
- 1.1.1 — 2022-03-18
- 1.1.0 — 2022-03-18
- 1.0.2 — 2022-03-18
- 1.0.1 — 2022-03-18
- 1.0.0 — 2022-03-18

## README

# pgsqlinfo

TypeScript library to work with information schema of PostgreSQL.

TypeScript models have been prepared based on the following links:

* https://www.postgresql.org/docs/current/information-schema.html
* https://www.postgresql.org/docs/current/infoschema-schemata.html
* https://www.postgresql.org/docs/current/infoschema-tables.html
* https://www.postgresql.org/docs/current/infoschema-columns.html
* https://www.postgresql.org/docs/current/infoschema-domains.html
* https://www.postgresql.org/docs/current/infoschema-user-defined-types.html
* https://www.postgresql.org/docs/current/infoschema-attributes.html

such as:

```typescript
export interface PgSchema {
  catalog_name:                  string | null;
  default_character_set_catalog: string | null;
  default_character_set_name:    string | null;
  default_character_set_schema:  string | null;
  schema_name:                   string | null;
  schema_owner:                  string | null;
  sql_path:                      string | null;
}
```

## Requirements

* [Node.js](https://nodejs.org/en/) - use active LTS

## Development

```sh
# clone repo
npm i
npm run build
# copy .env.sample as .env and edit settings
# NOTE: tests require a PostgreSQL server
npm run test
npm run test:coverage
```

## Usage

```sh
npm i pgsqlinfo
```

```typescript
import { Pool } from 'pg';
import { PgInfoService } from 'pgsqlinfo';

main();

async function main() {
  const dbName = process.env.PGDATABASE ?? '';
  const db = new Pool(); // relying on env settings
  const pgInfo = new PgInfoService(db, dbName, console);

  const schemaRecords = await pgInfo.schemata();
  console.log({ schemaRecords });

  const schema = pgInfo.schema('public');
  const tableRecords = await schema.tables();
  console.log({ tableRecords });

  // all columns of all tables
  // const columnRecords = await schema.columns();

  const usersTable = schema.table('users');
  const columnRecordsOfUsersTable = await usersTable.columns();
  console.log({ columnRecordsOfUsersTable });
}
```

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