I am trying to query a table named "client" of my Cloud SQL database.I am using cloud functions to access Cloud SQL. When I make the query, I get the following error:
relation "client" does not exist
I want to list all the clients in my table. When I run the same command from psql in cloud shell, I get the correct result:
postgres=> SELECT * FROM client LIMIT 2 ;
numcli | nom | prenom | ville | tel
--------+-----------+------------+-------------+------------
0 | Ernaut | Bernadette | marseille | 0296645394
1 | Christian | Louis | montpellier | 0417103362
(2 rows)
postgres=>
But the following code in Cloud Functions encounters an error:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import * as pg from "pg";
export const sendMoney = functions.https.onCall(async (data, context) => {
console.log(data);
if (!context.auth || !context.auth.uid)
throw new functions.https.HttpsError(
"unauthenticated",
"L'action est refusée car aucun utilisateur n'est connecté"
);
const pgConfig = {
max: 1,
user: "postgres",
password: "******",
database: "pay",
host: "/cloudsql/******:us-central1:****"
};
let pgPool;
if (!pgPool) {
pgPool = new pg.Pool(pgConfig);
}
return pgPool
.query("SELECT * FROM client LIMIT 2")
.then(result => {
console.log(" \n RESULT \n");
console.log(result);
};
})
.catch(e => {
console.log(e);
});
});
SELECT table_name FROM information_schema.tables WHERE table_schema='public'from inside the function?