Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions docs/examples/connectors/postgresql/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"ok": true,
"rows": [
{
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com",
"created_at": "2023-11-23T12:00:00.000Z",
"updated_at": "2023-11-23T12:00:00.000Z",
"active": true,
"role": "admin"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane.smith@example.com",
"created_at": "2023-11-23T11:30:00.000Z",
"updated_at": "2023-11-23T11:30:00.000Z",
"active": true,
"role": "user"
}
],
"rowCount": 2,
"command": "SELECT",
"fields": [
{
"name": "id",
"dataTypeID": 23,
"dataType": "int4"
},
{
"name": "name",
"dataTypeID": 1043,
"dataType": "varchar"
},
{
"name": "email",
"dataTypeID": 1043,
"dataType": "varchar"
},
{
"name": "created_at",
"dataTypeID": 1184,
"dataType": "timestamptz"
},
{
"name": "updated_at",
"dataTypeID": 1184,
"dataType": "timestamptz"
},
{
"name": "active",
"dataTypeID": 16,
"dataType": "bool"
},
{
"name": "role",
"dataTypeID": 1043,
"dataType": "varchar"
}
]
}
92 changes: 92 additions & 0 deletions docs/examples/connectors/postgresql/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node
// Mock PostgreSQL exec-rpc wrapper for admission testing
// Simulates vejas-postgresql binary that accepts JSON requests on stdin

import readline from 'readline';

const users = [
{
id: 1,
name: 'John Doe',
email: 'john.doe@example.com',
created_at: '2023-11-23T12:00:00.000Z',
updated_at: '2023-11-23T12:00:00.000Z',
active: true,
role: 'admin'
},
{
id: 2,
name: 'Jane Smith',
email: 'jane.smith@example.com',
created_at: '2023-11-23T11:30:00.000Z',
updated_at: '2023-11-23T11:30:00.000Z',
active: true,
role: 'user'
}
];

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

rl.on('line', (line) => {
try {
const request = JSON.parse(line);

if (request.op === 'query') {
// Simple SELECT query simulation
if (request.sql.toLowerCase().includes('select')) {
const response = {
ok: true,
rows: users,
rowCount: users.length,
command: 'SELECT',
fields: [
{ name: 'id', dataTypeID: 23, dataType: 'int4' },
{ name: 'name', dataTypeID: 1043, dataType: 'varchar' },
{ name: 'email', dataTypeID: 1043, dataType: 'varchar' },
{ name: 'created_at', dataTypeID: 1184, dataType: 'timestamptz' },
{ name: 'updated_at', dataTypeID: 1184, dataType: 'timestamptz' },
{ name: 'active', dataTypeID: 16, dataType: 'bool' },
{ name: 'role', dataTypeID: 1043, dataType: 'varchar' }
]
};
console.log(JSON.stringify(response));
} else {
console.log(JSON.stringify({
ok: false,
error: 'Only SELECT queries are supported in mock'
}));
}
} else if (request.op === 'execute') {
// INSERT/UPDATE/DELETE simulation
const response = {
ok: true,
rowCount: 1,
command: request.sql.split(' ')[0].toUpperCase()
};
console.log(JSON.stringify(response));
} else if (request.op === 'transaction') {
// Transaction simulation
const response = {
ok: true,
results: request.queries.map(() => ({ ok: true, rowCount: 1 }))
};
console.log(JSON.stringify(response));
} else {
console.log(JSON.stringify({
ok: false,
error: `Unknown operation: ${request.op}`
}));
}
} catch (err) {
console.log(JSON.stringify({
ok: false,
error: err.message
}));
}
});

console.error('Mock PostgreSQL connector started');
3 changes: 3 additions & 0 deletions docs/examples/connectors/postgresql/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CMD": "node mock.mjs"
}
55 changes: 55 additions & 0 deletions docs/examples/connectors/postgresql/postgresql.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# connector: postgresql — Comprehensive PostgreSQL database integration
#
# Platform connector for PostgreSQL database. Supports multiple operations:
# - Query execution (SELECT, INSERT, UPDATE, DELETE)
# - Transaction management (BEGIN, COMMIT, ROLLBACK)
# - Prepared statements (parameterized queries)
# - Bulk operations (COPY, batch inserts)
# - Schema introspection (list tables, columns, indexes)
#
# Uses exec-rpc driver wrapping a PostgreSQL client process. The process accepts
# JSON requests on stdin and returns JSON responses on stdout.
#
# Subjects:
# REQUEST: vxrpc.postgresql (outside vx.* namespace for request/reply)
#
# Secrets:
# postgresql/host - PostgreSQL server host
# postgresql/port - PostgreSQL server port (default: 5432)
# postgresql/database - Database name
# postgresql/user - Database user
# postgresql/password - Database password
#
# Rate limits: Depends on server configuration and connection pool size
# Connection pooling: Managed by the exec process
#
# Request format (JSON on stdin):
# {"op":"query","sql":"SELECT * FROM users WHERE id = $1","params":[123]}
# {"op":"execute","sql":"INSERT INTO users (name, email) VALUES ($1, $2)","params":["John","john@example.com"]}
# {"op":"transaction","queries":[{"sql":"...","params":[]}]}
#
# Response format (JSON on stdout):
# {"ok":true,"rows":[{"id":123,"name":"John"}],"rowCount":1}
# {"ok":false,"error":"relation \"users\" does not exist"}
#
# Note: This connector requires a PostgreSQL client wrapper binary (e.g., vejas-postgresql)
# that implements the exec-rpc protocol. The binary would use a PostgreSQL driver
# (e.g., tokio-postgres in Rust) to execute queries.

driver "exec-rpc"

# Request/reply subject (outside vx.* namespace)
REQUEST_SUBJECT = "vxrpc.postgresql"

# PostgreSQL client wrapper command
CMD = "/opt/vejas/vejas-postgresql"

# Environment variables for connection
ENV = {
PGHOST: secret("postgresql/host"),
PGPORT: secret("postgresql/port"),
PGDATABASE: secret("postgresql/database"),
PGUSER: secret("postgresql/user"),
PGPASSWORD: secret("postgresql/password"),
PGSSLMODE: "prefer"
}
Loading