0

I am using IBM Cloud Functions to convert the audio file into text and I am using IBM Watson speech to text service for that. Here I want to store the transcript to PostgreSQL Database. Is there any connection between IBM Cloud Functions and Compose for PostgreSQL service, So that I can store transcript to database.

I am using Node Runtime in cloud function.

Mdumanoj
  • 517
  • 3
  • 9
  • 27
  • have you tried using a node module like [`pg`](https://www.npmjs.com/package/pg)? not sure if you have seen this example which [shows you how to connect to an IBM Compose for PostgreSQL for Bluemix service using Node.js](https://github.com/IBM-Cloud/compose-postgresql-helloworld-nodejs) – vabarbosa Jan 08 '18 at 16:03
  • @Mdumanoj - Did the information above help you? – William 'Bill' Wentworth Jan 15 '18 at 20:01

1 Answers1

0

Using the Node.js module pg that is included in the Cloud Functions runtime works well. The following is a function stub that works for me (taken from this GitHub repo):

function myactualfunc(connection, some params) {
  const client=new Client({
    connectionString: connection['postgres']['composed'][0],
    ssl: true
  });

  return client.connect()
     .then(() =>
          client.query(
            "select ....",
            query-parameters))
     .then(res => perform some processing here)
     .then(() => client.end())
     .then(() => {return {"result": my-result} })
     .catch(e => {return {"error": e}})
}

function main({some params, __bx_creds: {'databases-for-postgresql': {connection}}}) {
    return myactualfunc(connection,some params);
}
data_henrik
  • 16,724
  • 2
  • 28
  • 49