Socket
Socket
Sign inDemoInstall

@pgkit/schemainspect

Package Overview
Dependencies
47
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pgkit/schemainspect

SQL Schema Inspection for PostgreSQL


Version published
Maintainers
1
Created

Readme

Source

schemainspect: SQL Schema Inspection for PostgreSQL

Inspects tables, views, materialized views, constraints, indexes, sequences, enums, functions, and extensions. Handles table partitioning and inheritance.

A port of @djrobstep's python schemainspect library.

Limitations: Function inspection only confirmed to work with SQL/PLPGSQL languages so far.

Basic Usage

Install with npm:

npm install @pgkit/schemainspect

Get an inspection object from an already opened SQLAlchemy session or connection as follows:

import {PostgreSQL} from '@pgkit/schemainspect'

const inspector = await PostgreSQL.create('postgresql://')

console.log(inspector.tables)
console.log(inspector.views)
console.log(inspector.functions)

console.log(inspector.tables[`"public"."mytable"`].schema)
console.log(inspector.tables[`"public"."mytable"`].name)
console.log(inspector.tables[`"public"."mytable"`].columns.mycolumn.dbtype)
console.log(inspector.tables[`"public"."mytable"`].columns.mycolumn.is_nullable)

The inspection object has attributes for tables, views, and all the other things it tracks. At each of these attributes you'll find a dictionary (Record<string, ...>) mapping from fully-qualified-and-quoted-name-of-thing-in-database to information object.

For instance, the information about a table books would be accessed as follows:

>>> books_table = i.tables['"public"."books"']
>>> books_table.name
'books'
>>> books_table.schema
'public'
>>> [each.name for each in books_table.columns]
['id', 'title', 'isbn']

Documentation

Documentation is a bit patchy at the moment. Watch this space!

Author Credits

Initial development, maintenance:

  • djrobstep

TypeScript port:

Contributions:

FAQs

Last updated on 03 Jun 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc