1.4.6 • Published 2 years ago

pgsqlinfo v1.4.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

pgsqlinfo

TypeScript library to work with information schema of PostgreSQL.

TypeScript models have been prepared based on the following links:

such as:

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

Development

# 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

npm i pgsqlinfo
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 });
}
1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago