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>>"
- var express = require('express');
- var app = express();
- const { Pool } =require('postgres-pool');
- const QUERY="SELECT * from information_schema.tables where table_schema = 'public'"
- const pool = new Pool({
- connectionString: 'postgres://user_name:password@127.0.0.1/db_name',
- });
- function getDBdata() {
- return new Promise((resolve, reject) => {
- pool.query(QUERY).then(queryResponse => {
- resolve(queryResponse.rows);
- }).catch(err => {
- reject(err);
- })
- });
- }
- app.get('/query', function (req, res) {
- getDBdata().then(
- rows => {
- var html = "<h1> List of Tables in DB</h1>";
- rows.forEach(element => {
- html = html.concat('<li>' + element.table_name + '</li><br/>');
- });
- res.send(html);
- }).catch(err => {
- console.log(err);
-
- })
- });
- module.exports = app;
Announcements
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
[Webinar] Upgrade Retail Experiences with Serverless & AI
Ever wondered if you could build lightning-fast, intelligent retail solutions and experiences without touching infrastructure? Join our upcoming live session to explore how you can combine the agility of serverless with the power of large language models
[Webinar] Powering Industry Innovation: Building Unified Solutions with Catalyst
Struggling with fragmented apps or patchwork workflows across teams? Join us for a practical session on how developers are building unified, scalable industry solutions using Catalyst by Zoho—without wrangling with infrastructure. In this live session,