Q:

where clause in serverless framework + postgresql

I am mobile developer trying to deploy Restful Api for testing purposes using serverless framework and postgresql. I manage to get it working but only with simple CRUD (getAll, getById, delete, insert)those functions that found on the postgresql. What if I need to execute query like "Select * from table_name where x = xx " 
Here is what I do to get user by Id in my handler.js
module.exports.getUser = (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false;
  db.getById('users', event.pathParameters.id)
    .then(res => {      
      callback(null,{
        statusCode: 200,
        headers: {
          "Content-Type": "application/json"
      },
        body: JSON.stringify(res)
      })
    })
    .catch(e => {
      callback(null,{
        statusCode: e.statusCode || 500,
        body: "Could not find User " + e
      })
    })
};

what if I need to get users where they belong to class A? I need to write normal query and pass it so it can be executed.

A:

I suppose you are using an ORM for postgress. You can check the documents of the ORM provider you are using.
For using queries I suggest node-postgress 
node-postgres is a collection of node.js modules for interfacing with your PostgreSQL database.
then an example using node-postgress:
exports.handler = async (event) => {
  const { Client } = require('pg')  //  Needs the nodePostgres Lambda Layer
  const client = new Client()
  await client.connect()

  const res = await client.query(
    'SELECT $1::text as message', 
    ['Hello world!'])
  console.log(res.rows[0].message)  // Shows "Hello world!""
  await client.end()

  const response = {
      statusCode: 200,
      result: res.rows[0].message
  };
  return response;
};

Note: you can write any query.

