/pgdbm:standalone-servicefrom pgdbm
Use when building simple standalone service or microservice with its own database - provides complete setup without shared pool complexity
Ships in pgdbm. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Core Principle: Create own pool with DatabaseConfig, run migrations, use database.
Simplest pgdbm pattern for services that own their database.
From pgdbm:choosing-pattern skill - use when:
from pgdbm import AsyncDatabaseManager, AsyncMigrationManager, DatabaseConfig
# Create configuration
config = DatabaseConfig(
connection_string="postgresql://localhost/myservice",
min_connections=5,
max_connections=20,
)
# Create database manager
db = AsyncDatabaseManager(config)
await db.connect()
# Run migrations
migrations = AsyncMigrationManager(
db,
migrations_path="./migrations",
module_name="myservice" # Required
)
result = await migrations.apply_pending_migrations()
# Use database
user_id = await db.execute_and_return_id(
"INSERT INTO {{tables.users}} (email, name) VALUES ($1, $2)",
"[email protected]",
"Alice"
)
# Cleanup (on shutdown)
await db.disconnect()
That's it. Complete standalone setup.
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from pgdbm import AsyncDatabaseManager, AsyncMigrationManager, DatabaseConfig
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup: Create database connection
config = DatabaseConfig(
connection_string="postgresql://localhost/myapp",
min_connections=5,
max_connections=20,
)
db = AsyncDatabaseManager(config)
await db.connect()
# Run migrations
migrations = AsyncMigrationManager(
db,
migrations_path="./migrations",
module_name="myapp"
)
await migrations.apply_pending_migrations()
# Store in app state
app.state.db = db
yield
# Shutdown: Close connection
await db.disconnect()
app = FastAPI(lifespan=lifespan)
@app.post("/users")
async def create_user(email: str, name: str, request: Request):
db = request.app.state.db
user_id = await db.execute_and_return_id(
"INSERT INTO {{tables.users}} (email, name) VALUES ($1, $2)",
email,
name
)
return {"id": user_id, "email": email}
@app.get("/users/{user_id}")
async def get_user(user_id: int, request: Request):
db = request.app.state.db
user = await db.fetch_one(
"SELECT * FROM {{tables.users}} WHERE id = $1",
user_id
)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
myservice/
├── main.py # FastAPI app or entry point
├── migrations/
│ ├── 001_create_users.sql
│ ├── 002_create_posts.sql
│ └── 003_add_indexes.sql
├── tests/
│ ├── conftest.py
│ └── test_users.py
├── .env # DATABASE_URL
└── pyproject.toml
# .env
DATABASE_URL=postgresql://user:password@localhost:5432/myservice
import os
from pgdbm import DatabaseConfig
# Load from environment
config = DatabaseConfig(
connection_string=os.getenv("DATABASE_URL"),
min_connections=int(os.getenv("DB_MIN_CONN", "5")),
max_connections=int(os.getenv("DB_MAX_CONN", "20")),
)
import asyncio
from pgdbm import AsyncDatabaseManager, AsyncMigrationManager, DatabaseConfig
async def process_job(db, job):
"""Process a single job."""
result = await do_work(job)
await db.execute(
"INSERT INTO {{tables.job_results}} (job_id, result) VALUES ($1, $2)",
job.id,
result
)
async def main():
# Setup database
config = DatabaseConfig(
connection_string="postgresql://localhost/worker",
min_connections=2,
max_connections=10,
)
db = AsyncDatabaseManager(config)
await db.connect()
# Run migrations
migrations = AsyncMigrationManager(
db,
migrations_path="./migrations",
module_name="worker"
)
await migrations.apply_pending_migrations()
# Worker loop
while True:
job = await get_next_job()
if job:
await process_job(db, job)
else:
await asyncio.sleep(1)
if __name__ == "__main__":
asyncio.run(main())
Even standalone services can use schemas:
config = DatabaseConfig(
connection_string="postgresql://localhost/mydb",
schema="myservice", # Service gets own schema
min_connections=5,
max_connections=20,
)
db = AsyncDatabaseManager(config)
await db.connect()
# Migrations automatically go to "myservice" schema
migrations = AsyncMigrationManager(
db,
migrations_path="./migrations",
module_name="myservice"
)
await migrations.apply_pending_migrations()
# All queries automatically scoped to schema
# {{tables.users}} → "myservice".users
When to use schema:
# tests/conftest.py
from pgdbm.fixtures.conftest import *
# tests/test_users.py
async def test_create_user(test_db):
"""Test user creation."""
# Apply your migrations to test database
migrations = AsyncMigrationManager(
test_db,
migrations_path="./migrations",
module_name="test"
)
await migrations.apply_pending_migrations()
# Test your code
user_id = await test_db.execute_and_return_id(
"INSERT INTO {{tables.users}} (email) VALUES ($1)",
"[email protected]"
)
assert user_id == 1
Don't use standalone if:
Standalone is for truly independent services.
That's the complete standalone pattern.
pgdbm:choosing-patternpgdbm:using-pgdbmpgdbm:core-api-reference, pgdbm:migrations-api-referencepgdbm:testing-database-codeWhat SKILL.md sets; muted values are Claude Code's defaults
9 skills in this plugin
/choosing-patternUse when deciding which pgdbm pattern to use (standalone, dual-mode library, or shared pool) - provides decision tree based on deployment context without requiring doc exploration/common-mistakesUse before implementing pgdbm patterns to avoid common mistakes - provides rationalization table and red flags that prevent pool multiplication, schema errors, and template syntax violations/core-api-referenceUse when implementing pgdbm database operations - provides complete AsyncDatabaseManager and DatabaseConfig API with all methods and parameterspgdbm@juanre-ai-tools is listed by juanre/ai-tools — review the source before installing
npx claudepluginhub juanre/ai-tools --plugin pgdbmOther plugins' skills for the same job