PostgreSQL

Run queries, insert, update, and delete rows in a PostgreSQL database.

Data and storageCredentials form1 actionAll integrations

On this page
  1. Connect
  2. Call it from a workflow
  3. Actions (1)
  4. run-query
  5. Details

Connect

Auth type: Credentials form (custom_auth). Pass the fields the provider needs (listed below) as the connection's credentials. They are sealed at rest.

FieldTypeDescription
hostrequiredtextDatabase server hostname or IP address
portrequiredtextDatabase server port (default 5432)
userrequiredtextDatabase username
passwordrequiredsecretDatabase password
databaserequiredtextDatabase name to connect to
  • From your agent: integrations {action: "connect", piece, credentials, env} stores the credentials for dev, prod or all. Answers name the fields, never the values.
  • Or set the integration's project secrets with the secrets tool (SLACK_BOT_TOKEN, DISCORD_WEBHOOK_URL, TELEGRAM_BOT_TOKEN, TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN …): a call uses the connection, else those secrets. integrations {action: "catalog", piece} lists which ones work.
  • Try one action now with integrations {action: "call", piece, piece_action, input}. It really sends.

Call it from a workflow

step.ctx.integrations.invoke("postgres", action, input) resolves with the provider's answer and rejects when PostgreSQL isn't connected or refuses. Wrap it in step.run so a retry sends once. See step.ctx. Its actions run through the integration runner, which the server's operator turns on: integrations {action: "catalog", piece: "postgres"} says whether yours can call it.

Workflow
// workflows/notify.ts: call PostgreSQL when a booking is confirmed
import { on } from "@appbricx/workflows";

export const tellPostgres = on.transition("booking", "status", "confirmed", async (_event, step) => {
  // Recorded once: a retry doesn't send it twice. Rejects when PostgreSQL isn't connected.
  const output = await step.run("PostgreSQL", () =>
    step.ctx.integrations.invoke("postgres", "run-query", {
      "query": "<query>"
    }),
  );
  step.ctx.log("PostgreSQL answered", output);
});
Try it from your agent
{
  "name": "integrations",
  "arguments": {
    "project_id": "<project-id>",
    "action": "call",
    "piece": "postgres",
    "piece_action": "run-query",
    "input": {
      "query": "<query>"
    },
    "env": "dev"
  }
}
From another backend (connector proxy)
curl -X POST "$APP_ORIGIN/__appbricx/connector-proxy/postgres/run-query" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "content-type: application/json" \
  -d '{"props":{"query":"<query>"}}'

Actions

run-query

Run Query. Run Query

Also accepted as run_query.

InputTypeDescription
queryrequiredtextPlease use $1, $2, etc. for parameterized queries to avoid SQL injection.
argsoptionalarrayArguments to be used in the query
query_timeoutoptionalnumberAn integer indicating the maximum number of milliseconds to wait for a query to complete before timing out.
connection_timeout_msoptionalnumberAn integer indicating the maximum number of milliseconds to wait for a connection to be established before timing out.
application_nameoptionaltextA string indicating the name of the client application connecting to the server.

Details

Id
postgres
Category
Data and storage
Tags
database, sql, relational, open-source
Package
@activepieces/piece-postgres@0.2.3
Runs
Through the integration runner