Reputation: 527
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.
Upvotes: 0
Views: 558
Reputation: 17118
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);
}
Upvotes: 0