Connecting to an SQL database through Catalyst functions

Connecting to an SQL database through Catalyst functions

Hey there, 

Are you looking to connect to a PostgreSQL database. Here is a sample Nodejs function that can connect to a database remotely and provide scalable API endpoint to retrieve list of tables.
Here, the GET method is 'GET' and the endpoint is '/query'.

Make sure that you install express and postgres-pool packages in your advanced I/O function using "npm install --save  <<package_name>>"
  1. var express = require('express');
  2. var app = express();
  3. const { Pool } =require('postgres-pool');
  4. const QUERY="SELECT * from information_schema.tables where table_schema = 'public'"
  5. const pool = new Pool({
  6. connectionString: 'postgres://user_name:password@127.0.0.1/db_name',
  7. });
  8. function getDBdata() {
  9. return new Promise((resolve, reject) => {
  10. pool.query(QUERY).then(queryResponse => {
  11. resolve(queryResponse.rows);
  12. }).catch(err => {
  13. reject(err);
  14. })
  15. });
  16. }
  17. app.get('/query', function (req, res) {
  18. getDBdata().then(
  19. rows => {
  20. var html = "<h1> List of Tables in DB</h1>";
  21. rows.forEach(element => {

  22. html = html.concat('<li>' + element.table_name + '</li><br/>');
  23. });
  24. res.send(html);
  25. }).catch(err => {
  26. console.log(err);
  27. })
  28. });

  29. module.exports = app;

    • Announcements

    • React Nexus 2025 Recap: Catalyst Slate in Action!

      Hey Catalyst Community! We recently attended the React Nexus 2025 conference, an exciting gathering for frontend enthusiasts and React developers. Our team had an incredible time presenting and conducting a hands-on workshop on Catalyst Slate, our streamlined
    • [Webinar] A hands-on guide to Catalyst Stratus

      Have you used Catalyst Stratus yet? It’s an object storage service that makes it easy to handle large files — whether they're coming from your Catalyst app or other Zoho apps. We’re hosting a live coding session where you’ll build a working prototype
    • Catalyst Video Tutorials!

      Hello everyone! We’ve been brewing something exciting behind the scenes, and we’re thrilled to finally share it with you- Catalyst video tutorials are here! We recognized that videos are the predominant medium for learning and discovery these days, so
    • [Webinar] Catalyst Cloud Browser in Action: PDF & Web Rendering Solutions for Regulated Industries

      Hi everyone, Have you ever struggled with rigid PDF tools or clunky rendering logic in BFSI or healthcare apps? Do your clients struggle to deliver compliant, dynamic, and automated documents — and most are still stuck with brittle, server-heavy PDF generation?
    • Announcing Catalyst Developer Bootcamps in India - Zoho Community

      Hey everyone! We're excited to announce a set of developer bootcamps dedicated to Catalyst! These bootcamps are aimed to empower developers to build, scale, and deploy applications with speed and precision, using Catalyst. Whether you're a newcomer or

      Catalyst Community