Skip to content

nicferrier/psql-express-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A PSQL webapp

This is an Express app that will allow implement a PSQL like query tool in your browser.

It looks like this:

Web interface to PostgreSQL

Install

Just:

npm install psql-web-app

How to use it

In your Express app, you need something like:

const express = require("express");
const psqlWebApp = require("psql-web-app");
const { Pool } = require('pg');

const pool = new Pool(databaseConfig); // your own db connection details
const app = express();

app.query = function (sql, parameters) {
   let client = await pool.connect();
   let result = await client.query(sql, parameters);
   return result;
};

psqlWebApp.init(app);

in other words you need to implement a query function which will return a result-set; the function needs to be added to the app object which psqlWebApp.init receives.

See here for details on the databaseConfig for the pg library.

Options

You can also pass in a middleware function to be added to all the routes handlers for the PSQL web app so that you can use authentication or such like.

Like so:

psqlWebApp.init(app, {
  middleware: function (request, response, next) {
     console.log("logging path middleware", request.path);
     next();
  }
});

The middleware functions must be valid Express middleware.

If you want a list of middleware you'll need to implement that yourself, within a single middleware.

About

An Express app a bit like PSQL for Postgres.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published