{"id":16758408,"url":"https://github.com/kessler/pg-schema","last_synced_at":"2025-04-10T17:13:57.263Z","repository":{"id":17299267,"uuid":"20069719","full_name":"kessler/pg-schema","owner":"kessler","description":"create a schema object by querying the metadata tables of postgresql/redshift","archived":false,"fork":false,"pushed_at":"2016-08-03T15:26:35.000Z","size":13,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T03:31:53.262Z","etag":null,"topics":[],"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/kessler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-22T17:08:29.000Z","updated_at":"2019-08-13T15:42:12.000Z","dependencies_parsed_at":"2022-07-26T16:32:04.764Z","dependency_job_id":null,"html_url":"https://github.com/kessler/pg-schema","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpg-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpg-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpg-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kessler%2Fpg-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kessler","download_url":"https://codeload.github.com/kessler/pg-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154984,"owners_count":21056543,"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":[],"created_at":"2024-10-13T04:05:11.038Z","updated_at":"2025-04-10T17:13:57.244Z","avatar_url":"https://github.com/kessler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DEPRECATED - Try [pg-metadata](https://github.com/ironsource/node-pg-metadata) instead\n\npg-schema\n---------\n\ncreate a schema object by querying the metadata tables of postresql\n\n\n```javascript\t\n    var connection = /* anything that exposes a .query('sql', params, function(err, results) {}) interface to a postgresql server */\n    var validate = require('validate-schema')\n    var pgSchema = require('pg-schema')\n\n    pgSchema(connection, /* tableName, schemaName, databaseName */, function(err, schema) {\n        \n    })\n```\n\n#### Doing it yourself\ninstead of letting pgSchema run the query, you can run it yourself:\n```javascript\n    var pgSchema = require('pg-schema')\n    var validate = require('validate-schema')\n\n    var query = pgSchema.createQuery(/* tableName, ,schemaName, databaseName */)\n\n    // run the query and when you get the result set do:\n    var schema = pgSchema.createMetadataObject(resultSet, 'mytable')\n    validate({ mytable: { a: 1 }}, schema)\n```\nPlease note that the schema object does not maintain information about database and database schema. Those are only used when query the meta data tables of the database\n\n#### change schema output\nsometimes you just want a table: { fields } result:\n```javascript\n    var connection = /* anything that exposes a .query('sql', params, function(err, results) {}) interface to a postgresql server */\n    var validate = require('validate-schema')\n    var pgSchema = require('pg-schema')\n    \n    pgSchema.simpleFields(true)\n\n    pgSchema(connection, 'mytable' /*,schemaName, databaseName*/, function(err, schema) {\n        console.log(schema) // { mytable: { a: 'varchar' }}\n    })\n```\n\nEarlier versions of this module were designed to work with [validate-schema](https://github.com/segmentio/validate-schema) in the same way [auto-schema](https://github.com/segmentio/auto-schema) does, but the newer ones is not\n\nTODO:\n- Add an enhanced version with more details (this will not be compatible with pg-validate), maybe in a new module ?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fpg-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkessler%2Fpg-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkessler%2Fpg-schema/lists"}