https://github.com/kessler/pg-schema
create a schema object by querying the metadata tables of postgresql/redshift
https://github.com/kessler/pg-schema
Last synced: 22 days ago
JSON representation
create a schema object by querying the metadata tables of postgresql/redshift
- Host: GitHub
- URL: https://github.com/kessler/pg-schema
- Owner: kessler
- License: mit
- Created: 2014-05-22T17:08:29.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-08-03T15:26:35.000Z (over 8 years ago)
- Last Synced: 2025-04-04T03:31:53.262Z (29 days ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEPRECATED - Try [pg-metadata](https://github.com/ironsource/node-pg-metadata) instead
pg-schema
---------create a schema object by querying the metadata tables of postresql
```javascript
var connection = /* anything that exposes a .query('sql', params, function(err, results) {}) interface to a postgresql server */
var validate = require('validate-schema')
var pgSchema = require('pg-schema')pgSchema(connection, /* tableName, schemaName, databaseName */, function(err, schema) {
})
```#### Doing it yourself
instead of letting pgSchema run the query, you can run it yourself:
```javascript
var pgSchema = require('pg-schema')
var validate = require('validate-schema')var query = pgSchema.createQuery(/* tableName, ,schemaName, databaseName */)
// run the query and when you get the result set do:
var schema = pgSchema.createMetadataObject(resultSet, 'mytable')
validate({ mytable: { a: 1 }}, schema)
```
Please 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#### change schema output
sometimes you just want a table: { fields } result:
```javascript
var connection = /* anything that exposes a .query('sql', params, function(err, results) {}) interface to a postgresql server */
var validate = require('validate-schema')
var pgSchema = require('pg-schema')
pgSchema.simpleFields(true)pgSchema(connection, 'mytable' /*,schemaName, databaseName*/, function(err, schema) {
console.log(schema) // { mytable: { a: 'varchar' }}
})
```Earlier 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
TODO:
- Add an enhanced version with more details (this will not be compatible with pg-validate), maybe in a new module ?