Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-query-walker

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-query-walker

Analyzes a SQL query you pass in, and provides a list of all database tables and columns that the query references. Since it uses the PostgresQL query parser, it can process any valid PostgresQL query.

  • 1.0.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

pg-query-walker

This npm module walks thru any PostgresQL query, and enumerates all database tables and columns used.

Features

  • Uses the native query parser inside PostgresQL
  • Can analyze any valid PSQL query
  • Handles complex queries including WITH statements
  • Returns only real table names and column names
  • Ignores common table expressions and intermediate columns

Install

$ npm install pg-query-walker

Usage

// Use the file system module to read SQL files
// and the query walker to analyze them
const fs = require('fs');
const walker = require('pg-query-walker');

// Analyze SQL from a file
const analysis = walker.analyzeSQL(fs.readFileSync('pets.sql', 'utf8'));

// Display the results
console.log('Tables Used: ', analysis.tables);
console.log('Columns Used: ', analysis.columns);

SQL Input

SELECT name, born_at, a.name AS species FROM pets
INNER JOIN animals a ON a.id = pets.animal_id
ORDER BY born_at

JSON Output

{ 
  tables: ["animals", "pets"], 
  columns: { "animals.name", 
             "pets.born_at", 
             "pets.name" } 
}

Keywords

FAQs

Package last updated on 01 Feb 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc