# pg-schema

> validate data against a postgreSQL table

Latest version **1.0.1** (published 2016-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-schema
pnpm add pg-schema
yarn add pg-schema
bun add pg-schema
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-08-03 |
| First published | 2014-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Yaniv Kessler |
| Maintainers | yaniv, kessler |
| Keywords | postgreSQL, pg, postgre |

## Links

- npm: https://www.npmjs.com/package/pg-schema
- Repository: https://github.com/kessler/pg-schema
- Issues: https://github.com/kessler/pg-schema/issues
- npm.io page: https://npm.io/package/pg-schema

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^0.8.1
- [should](https://npm.io/package/should.md) ^6.0.3
- [pg-escape](https://npm.io/package/pg-escape.md) 0.0.2

## Recent versions

- 1.0.1 (latest) — 2016-08-03
- 0.2.0 — 2015-05-05
- 0.1.0 — 2014-11-18

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

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