{"id":19223610,"url":"https://github.com/wmfs/pg-info","last_synced_at":"2025-07-22T23:36:41.998Z","repository":{"id":21240008,"uuid":"136920965","full_name":"wmfs/pg-info","owner":"wmfs","description":"Grabs metadata from a PostgreSQL database.","archived":false,"fork":false,"pushed_at":"2025-07-12T04:07:28.000Z","size":462,"stargazers_count":6,"open_issues_count":3,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-12T06:11:54.326Z","etag":null,"topics":["package","postgresql","tymly"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wmfs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-11T12:08:09.000Z","updated_at":"2025-07-12T04:07:31.000Z","dependencies_parsed_at":"2023-09-27T21:25:18.637Z","dependency_job_id":"d7a7b05b-4b08-4949-a1bf-d1cc45741f43","html_url":"https://github.com/wmfs/pg-info","commit_stats":{"total_commits":411,"total_committers":17,"mean_commits":"24.176470588235293","dds":0.7226277372262774,"last_synced_commit":"6a493b79109601012c95164754c617bbe8e76d2e"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/wmfs/pg-info","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-info","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-info/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-info/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-info/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wmfs","download_url":"https://codeload.github.com/wmfs/pg-info/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-info/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264948660,"owners_count":23687536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["package","postgresql","tymly"],"created_at":"2024-11-09T15:08:57.419Z","updated_at":"2025-07-22T23:36:41.970Z","avatar_url":"https://github.com/wmfs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-info\n[![Tymly Package](https://img.shields.io/badge/tymly-package-blue.svg)](https://tymly.io/)\n[![npm (scoped)](https://img.shields.io/npm/v/@wmfs/pg-info.svg)](https://www.npmjs.com/package/@wmfs/pg-info)\n[![CircleCI](https://circleci.com/gh/wmfs/pg-info.svg?style=svg)](https://circleci.com/gh/wmfs/pg-info)\n[![codecov](https://codecov.io/gh/wmfs/pg-info/branch/master/graph/badge.svg)](https://codecov.io/gh/wmfs/pg-info)\n[![CodeFactor](https://www.codefactor.io/repository/github/wmfs/pg-info/badge)](https://www.codefactor.io/repository/github/wmfs/pg-info)\n[![Dependabot badge](https://img.shields.io/badge/Dependabot-active-brightgreen.svg)](https://dependabot.com/)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/wmfs/tymly/blob/master/packages/pg-concat/LICENSE)\n\n\t\n\u003e Grabs metadata from a PostgreSQL database\n\n## \u003ca name=\"install\"\u003e\u003c/a\u003eInstall\n```bash\n$ npm install pg-info --save\n```\n\n## \u003ca name=\"usage\"\u003e\u003c/a\u003eUsage\n\n```javascript\nconst pg = require('pg')\nconst pgInfo = require('@wmfs/pg-info')\n\n// Make a new Postgres client\nconst client = new pg.Client('postgres://postgres:postgres@localhost:5432/my_test_db')\nclient.connect()\n\nconst info = await pgInfo({\n    client: client,\n    schemas: [\n      'pginfo_people_test',\n      'pginfo_planets_test',\n      'pginfo_not_exists'\n    ]    \n})\n```\n\n## \u003ca name=\"api\"\u003e\u003c/a\u003eAPI\n\n### pgInfo(options, callback)\n\n### Options:\n| Option  | Notes |\n| ------  | ----- |\n| `client`  | An already-connected [pg client](https://github.com/brianc/node-postgres/wiki/Client) or [pg pool](https://github.com/brianc/node-postgres/wiki) instance to your database |\n| `schemas` | An array of schema names you'd like information about |\n\n\n## \u003ca name=\"output\"\u003e\u003c/a\u003eOutput\n\n\u003e Taking a look at [the tests](https://github.com/wmfs/pg-info/blob/master/test/tests.js) is a good place to get a feel for what __pg-info__ will produce.\n \n__In summary, the structure of the output is:__\n\n* `info` object\n    * `schema` object(s)\n        * `table` object(s)\n            * `column` object(s)\n            * `index` object(s)\n            * `trigger` object(s)           \n            * `fkConstraint` object(s)\n        * `view` object(s)\n            * `column` object(s)\n            * `trigger` object(s)\n \n### `info` object\n\n__Example__\n\n```javascript\n{\n  generated: '2017-05-21T21:53:42.594Z',\n  schemas: {} // Keys are schema names\n}\n```\n\n__Properties__\n\n| property | Type  | Notes |\n| -------- | ----- | ----- |\n| `generated` | `string` | Timestamp of when __pg-info__ interrogated the database |\n| `schemas` | `object` | An object where the key refers to a schema name provided via the options, and the value is a `schema` object |\n\n### `schema` object\n\n__Example__\n\n```javascript\n{\n  schemaExistsInDatabase: true,\n  comment: 'Simple schema created to support testing of the pg-info package!',\n  tables: {...} // Keys are table names\n}\n```\n\n__Properties__\n\n| property | Type | Notes   |\n| -------- | ---- | ------- |\n| `comment` | `string` | The database comment added for this schema, if available |\n| `schemaExistsInDatabase` | `boolean` | Indicates if this schema is present in the database or not |\n| `tables` | `object` | An object where the key refers to a table name within this schema, and the value is a `table` object |\n| `views` | `object` | An object where the key refers to a view name within this schema, and the value is a `view` object |\n\n### `table` object\n\n__Example__\n\n```javascript\n{\n  comment: 'For storing a list of planets',\n  pkColumnNames: [\n    'planet_name'\n  ],\n  columns: {...}, // Keys are column names\n  triggers: {...}, // Keys are trigger names\n  indexes: {...}, // Keys are index names\n  fkConstraints: {...} // Keys are foreign key constraint names\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `comment` | `string` |  The database comment added for this table, if available |\n| `pkColumnNames` | `[string]` | An array of column names that define this table's primary key |\n| `columns` | `object` | An object where the key refers to a column name within this table, and the value is a `column` object |\n| `indexes` | `object` | An object where the key refers to an index name defined for this table, and the value is an `index` object |\n| `triggers` | `object` | An object where the key refers to a trigger name within this table, and the value is a `trigger` object |\n| `fkConstraints` | `object` | An object where the key refers to a foreign-key constraint name defined for this table, and the value is a `fkConstraint` object |\n\n### `view` object\n\n__Example__\n\n```javascript\n{\n  columns: {...}, // Keys are column names\n  triggers: {...}, // Keys are trigger names\n  comment: 'View of just those planets in our solar system',\n  sql: 'SELECT * FROM my_schema.planets WHERE solar_system = true;'\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `columns` | `object` | An object where the key refers to a column name within this view, and the value is a `column` object |\n| `triggers` | `object` | An object where the key refers to a trigger name within this view, and the value is a `trigger` object |\n| `sql` | `string` |  The underlying SQL query of this view |\n| `comment` | `string` |  The database comment added for this view, if available |\n\n### `column` object\n\n__Example__\n\n```javascript\n{\n  array: false,\n  columnDefault: null,\n  isNullable: 'YES',\n  dataType: 'integer',\n  characterMaximumLength: null,\n  numericScale: 0,\n  comment: 'Age in years'\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `array` | `boolean` | Is the column an array? |\n| `comment` | `string` | The database comment added for this comment, if available |\n| `columnDefault` | `string` | The value used to default the value of this column |\n| `isNullable` | `string` | Indicates if null values are allowed in this column (`YES`) or not (`NO`) |\n| `dataType` | `string` | The PostgreSQL data type assigned to this column |\n| `characterMaximumLength` | `integer` | The maximum length of a string stored in this column | \n| `numericScale` | `integer` | For numeric columns, this refers to the number of digits permitted after the decimal point |\n\n### `index` object\n\n__Example__\n\n```javascript\n{\n  columns: [\n    [\n      'moons_id'\n    ]\n  ],\n  unique: false,\n  method: 'btree'\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `columns` | `[string]` | An array that contains the column names of the table that are covered by this index |\n| `unique` | `boolean` | Indicates whether this is a unique index or not |\n| `method` | `string` | The index method used, one of `btree`, `hash`, `gist` or `gin`) |\n\n### `trigger` object\n\n__Example__\n\n```javascript\n{\n  triggers: {\n    someInsertTriggerName: {\n      eventManipulation: 'INSERT',      \n      actionCondition: null,\n      actionStatement: 'EXECUTE PROCEDURE append_inserted_craters_row()',\n      actionOrientation: 'STATEMENT',\n      actionTiming: 'BEFORE'\n    }\n  }\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `eventManipulation` | `string` | Event that fires the trigger (`INSERT`, `UPDATE`, or `DELETE`) |\n| `actionCondition` | `string` | `WHEN` condition of the trigger, null if none (also null if the table is not owned by a currently enabled role) |\n| `actionStatement` | `string` | Statement that is executed by the trigger (currently always `EXECUTE PROCEDURE function(...)`) |\n| `actionOrientation` | `string` | Identifies whether the trigger fires once for each processed row or once for each statement (`ROW` or `STATEMENT`) |\n| `actionTiming` | `string` | Time at which the trigger fires (`BEFORE`, `AFTER`, or `INSTEAD OF`) |\n\n### `fkConstraint` object\n\n__Example__\n\n```javascript\n{\n  targetTable: 'pginfo_planets_test.moons',\n  sourceColumns: [\n    'moons_id'\n  ],\n  targetColumns: [\n    'id'\n  ],\n  updateAction: 'NO_ACTION',\n  deleteAction: 'CASCADE',\n  matchType: 'SIMPLE'\n}\n```\n\n__Properties__\n\n| property | Type | Notes |\n| -------- | ---- | ----- |\n| `targetTable` | `string` | The 'child' table that is related to this table - of the form `[schemaName].[tableName]` |\n| `sourceColumns` | `[string]` | An array of foreign-key column names on this table |\n| `targetColumns` | `[string]` | And this is an array of column names found the target table (often relating to its primary key) |\n| `updateAction` | `string` | Identifies the update action, either `NO ACTION`, `RESTRICT`, `CASCADE`, `SET NULL` or `SET DEFAULT` |\n| `deleteAction` | `string` | Identifies the delete action, either `NO ACTION`, `RESTRICT`, `CASCADE`, `SET NULL` or `SET DEFAULT` |\n| `matchType` | `string` | Identifies the match type, either `FULL`, `PARTIAL`, or `SIMPLE` |\n\n* Note the order of the columns provided in `sourceColumns` and `targetColumns` arrays correlate with each other.\n\n## \u003ca name=\"test\"\u003e\u003c/a\u003eTesting\n\nBefore running these tests, you'll need a test PostgreSQL database available and set a `PG_CONNECTION_STRING` environment variable to point to it, for example:\n\n```PG_CONNECTION_STRING=postgres://postgres:postgres@localhost:5432/my_test_db```\n\n\n```bash\n$ npm test\n```\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n[MIT](https://github.com/wmfs/pg-info/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmfs%2Fpg-info","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwmfs%2Fpg-info","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmfs%2Fpg-info/lists"}