Using PostgreSQL from a MoonBit Agent

SkillDatabases & data

Using golem:rdbms/postgres from a MoonBit Golem agent. Use when the user asks to connect to PostgreSQL, run SQL, or use PostgreSQL from MoonBit agent code.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Using PostgreSQL from a MoonBit Agent skill

What this skill tells your AI

The instructions your AI receives, as published by golemcloud/golem in golem-skills/skills/moonbit/golem-add-postgres-moonbit/SKILL.md and read by ahel’s review.

The MoonBit SDK already includes the generated package for golem:rdbms/postgres@1.5.0.

Add the Package Import

In the component's moon.pkg, add an alias for the package:

import {
  "golemcloud/golem_sdk/interface/golem/rdbms/postgres" @pg,
}

Open a Connection

let conn = @pg.DbConnection::open("postgres://user:password@localhost:5432/app")
  .or_error!("failed to connect to PostgreSQL")

Query Data

PostgreSQL placeholders use $1, $2, ...

let result = conn.query(
  "SELECT $1::text",
  [@pg.DbValue::Text("hello")],
).or_error!("query failed")

let row = result.rows[0]
let value = row.values[0]

let message = match value {
  @pg.DbValue::Text(value) => value
  @pg.DbValue::Varchar(value) => value
  @pg.DbValue::Bpchar(value) => value
  _ => abort("unexpected PostgreSQL value")
}

Execute Statements

conn.execute(
  "INSERT INTO notes (id, body) VALUES ($1, $2)",
  [@pg.DbValue::Int4(1), @pg.DbValue::Text("hello")],
).or_error!("insert failed")

Transactions

let tx = conn.begin_transaction().or_error!("failed to start transaction")
tx.execute(
  "UPDATE notes SET body = $1 WHERE id = $2",
  [@pg.DbValue::Text("updated"), @pg.DbValue::Int4(1)],
).or_error!("update failed")
tx.commit().or_error!("commit failed")

Signals

GitHub stars
2k
Forks
212
Last commit
Sep 2026

ahel review

  • S4info
    community integration — published by golemcloud, not postgres

Automated review, not a security audit. Ruleset v1.

Advanced
Catalog kind
skill
Gateway key
golem-add-postgres-moonbit
Source
github.com/golemcloud/golem