Parse Server: plain SQL query in the cloud code

Hello guys,

I use PostgreSQL as a backend for Parse Server and I’d like to run a plain SQL query in a cloud function. I understand that it’s a hackish way of doing things in Parse, but still. Could someone help me to find a way to use the system PostgreSQL connection (which is already in place after Parse Server has started) and run a query. I know I could create a brand new connection using some external package, but I’d prefer not to.

I see something like the following in PostgresStorageAdapter.js:

this._client
      .any('SELECT * FROM "_SCHEMA" WHERE "className"=$<className>', {
        className,
      })

This is exactly what I need, but I need this in the cloud code. Is it possible to get an instance of the PostgreSQL client there?

For all this kind of things, I use the Config static variable.
For instance, when looking for the MongoDB instance, I do :

const config = Config.get(Parse.applicationId);
const mongoAdapter = config.database.adapter;
await mongoAdapter.connect();
const collection = await mongoAdapter.database.collection(className);

1 Like