npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@streetjs/schema-inspector

v1.0.0

Published

StreetJS database schema introspection: a unified DatabaseSchema (tables, columns, primary keys, foreign keys, indexes) across PostgreSQL, MySQL/MariaDB, and SQLite, with TTL caching. Works with any queryable pool.

Readme

@streetjs/schema-inspector

The StreetJS database schema introspector: produces a unified DatabaseSchema — tables, columns, primary keys, foreign keys, and indexes — from a live PostgreSQL, MySQL/MariaDB, or SQLite database, with per-pool TTL caching. ESM, strict-TypeScript.

It talks only through a structural QueryablePool interface and routes by the pool's constructor name, so it has no dependency on any concrete pool implementation — the only dependency is @streetjs/postgres for the shared DbResult type.

This is the standalone home of the inspector that also backs the streetjs framework. The framework re-exports this package, so there is a single source of truth.

Install

npm install @streetjs/schema-inspector

Usage

import { SchemaInspector } from '@streetjs/schema-inspector';

// `pool` can be any object with `query(sql, params?): Promise<DbResult>`
// — PgPool, MysqlPool, and SqlitePool all qualify.
const schema = await SchemaInspector.inspect(pool);

for (const table of schema.tables) {
  console.log(table.name, table.primaryKey, table.columns.length);
}

API

SchemaInspector.inspect(pool, opts?): Promise<DatabaseSchema>

Introspects the database and returns its schema. Results are cached per pool for opts.ttlMs milliseconds (default 60000). The dialect is detected from the pool's constructor name (PgPool → PostgreSQL, SqlitePool → SQLite, anything else → MySQL/MariaDB).

SchemaInspector.invalidateCache(pool): void

Drops the cached schema for pool so the next inspect re-fetches.

Types

interface DatabaseSchema { tables: TableSchema[]; inspectedAt: Date }
interface TableSchema {
  name: string;
  columns: ColumnMeta[];
  primaryKey: string[];
  foreignKeys: FkMeta[];
  indexes: IndexMeta[];
}
interface ColumnMeta { name: string; type: string; nullable: boolean; default: string | null }
interface FkMeta { column: string; refTable: string; refColumn: string }
interface IndexMeta { name: string; columns: string[]; unique: boolean }
interface QueryablePool { query(sql: string, params?: unknown[]): Promise<DbResult> }

How it works

  • PostgreSQL — three round-trips against information_schema (columns + primary keys), referential_constraints (foreign keys), and pg_indexes (indexes, with the column list parsed from indexdef).
  • MySQL/MariaDBinformation_schema.COLUMNS/KEY_COLUMN_USAGE/STATISTICS, grouping the per-column STATISTICS rows into composite indexes.
  • SQLitesqlite_master for the table list, then PRAGMA table_info, index_list/index_info, and foreign_key_list per table.

All engines normalize into the same DatabaseSchema shape.

Example

A complete runnable example lives in src/examples/integration.ts:

npm run example -w packages/schema-inspector

License

MIT — see LICENSE.