indxflow
v1.0.0
Published
Ultra-fast, zero-dependency Serverless PostgreSQL HTTP Client, Type-Safe ORM & CLI for Indxflow DBaaS
Maintainers
Readme
⚡ Indxflow — Zero-Dependency Serverless PostgreSQL HTTP Client & Type-Safe ORM
Official ultra-fast, zero-dependency Serverless PostgreSQL HTTP Client, Type-Safe ORM & CLI for Indxflow DBaaS — the low-cost Serverless PostgreSQL API Gateway with automatic Scale-to-Zero ($1.00 = 100,000 queries).
🌟 Why Indxflow?
- 🪶 Zero Dependencies (< 5 KB): Built entirely on native
fetch. Zero binary engines (no Prisma 30MB+ cold-starts). - ⚡ Sub-5ms Latency: Parameterized HTTP SQL over persistent connections. Completely eliminates TCP connection pool exhaustion in serverless edge runtimes (Next.js 15, Vercel Edge, Cloudflare Workers, AWS Lambda).
- 🛡️ Type-Safe ORM & Query Builder: Fluent syntax (
db.from('users').select(...).where(...).orderBy(...)) with complete TypeScript column inference. - 🏷️ Tagged Template Literals (
sql): Safe parameter interpolation$1, $2...protecting against SQL injection vulnerabilities. - 💰 Scale-to-Zero & RFC 7807 Error Handling: Automatic parsing of token balances via
X-Tokens-Remainingand typedPaymentRequiredError(HTTP 402) when balance hits zero. - 🤖 Autonomous AI Agent Onboarding: Instant database provisioning via
Indxflow.provision()with 25,000 free starter tokens. - 🛠️ CLI Schema Codegen (
npx indxflow pull): Instantly pull remote PostgreSQL schema and generate TypeScript type definitions.
📦 Installation
npm install indxflow
# or
pnpm add indxflow
# or
yarn add indxflow🚀 1. Type-Safe ORM Usage
import { createOrm } from 'indxflow';
// 1. Define your database schema interface (or generate via `npx indxflow pull`)
interface AppSchema {
users: {
id: string;
email: string;
name: string;
age: number;
status: 'active' | 'banned';
created_at: string;
};
posts: {
id: string;
user_id: string;
title: string;
views: number;
};
}
// 2. Initialize ORM (reads INDXFLOW_API_KEY from environment)
export const db = createOrm<AppSchema>();
// 3. Type-Safe SELECT Query:
const activeUsers = await db.from('users')
.select('id', 'email', 'name')
.where('status', '=', 'active')
.andWhere('age', '>=', 18)
.orderBy('created_at', 'DESC')
.limit(10)
.execute();
console.log(activeUsers.rows); // Typed as Array<{ id: string; email: string; name: string }>
console.log(`Executed in ${activeUsers.latencyMs}ms. Tokens left: ${activeUsers.tokensRemaining}`);
// 4. Type-Safe INSERT with Returning:
const newUser = await db.into('users')
.values({
email: '[email protected]',
name: 'Alex',
age: 25,
status: 'active',
})
.onConflictDoNothing()
.returning('id', 'email')
.executeTakeFirstOrThrow();
// 5. Type-Safe UPDATE:
await db.update('users')
.set({ status: 'banned' })
.where('id', '=', 'usr_123')
.execute();
// 6. Type-Safe DELETE:
await db.deleteFrom('posts')
.where('views', '<', 5)
.execute();⚡ 2. Tagged Template SQL (sql)
For raw queries with automated parameter extraction:
import { Indxflow, sql } from 'indxflow';
const client = new Indxflow();
const minAge = 21;
const city = 'London';
const result = await client.sql`
SELECT id, name, email
FROM users
WHERE age >= ${minAge} AND city = ${city}
LIMIT 20
`;
console.log(result.rows);🔄 3. Atomic Transactions & Batching
Execute multiple operations in a single atomic HTTP round-trip:
const { result, totalLatencyMs } = await db.transaction(async (tx) => {
tx.add(
db.into('orders').values({ user_id: 'usr_1', amount: 150 })
);
tx.add(
db.update('users').set({ status: 'active' }).where('id', '=', 'usr_1')
);
});
console.log(`Transaction executed in ${totalLatencyMs}ms`);🛠️ 4. Indxflow CLI
Generate TypeScript types directly from your active database:
# Pull schema and create src/types/db.d.ts
npx indxflow pull
# Inspect database latency, tokens and server health
npx indxflow status🤖 5. Autonomous AI Agent Provisioning
import { Indxflow } from 'indxflow';
const provision = await Indxflow.provision({
email: '[email protected]',
db_name: 'my-agent-app',
agent_name: 'Claude Code',
});
console.log(`API Key: ${provision.api_key}`);
console.log(`Claim in Web Dashboard: ${provision.claim_url}`);🛡️ Error Handling & Scale-to-Zero
import { db, PaymentRequiredError, RateLimitError } from 'indxflow';
try {
const users = await db.from('users').selectAll().execute();
} catch (error) {
if (error instanceof PaymentRequiredError) {
console.error('Scale-to-Zero: Database tokens exhausted. Top up at https://indxflow.com');
} else if (error instanceof RateLimitError) {
console.warn('Rate limit exceeded (100 RPS).');
} else {
console.error('Query error:', error);
}
}📄 License
MIT © Indxflow
