Cloudflare Workers enables you to deploy serverless functions or entire application backends globally, drastically reducing latency between your application and users. Combined with Cloudflare Hyperdrive’s caching proxy capabilities, you can achieve exceptional database performance for your B2B applications.

Why Nile with Cloudflare?

Global Scale

Deploy your B2B applications worldwide using Cloudflare Workers, while Nile ensures tenant isolation, auth-scaling, and tenant insights.

Accelerated Performance

Leverage Cloudflare Hyperdrive to accelerate database queries, making interactions lightning-fast for your users.

Multi-Tenant Isolation

Nile’s tenant-aware architecture ensures that your customers’ data is securely isolated, enabling you to build scalable and compliant apps effortlessly.

Simplified Deployment

Combine Nile’s serverless Postgres with Cloudflare’s edge network to streamline the deployment of modern B2B applications with less operational overhead.

Optimized for AI Workloads

Build AI-driven, multi-tenant applications with Nile and deploy them globally with Cloudflare. This architecture minimizes latency while easily scaling to millions of embeddings.

Quick Start Guide

1

Create a Database

  1. Sign up and log in to Nile Console
  2. Create a new database
  3. Create your required tables using the SQL editor
  4. Get your connection string with credentials from the “Connect” tab
2

Clone the Example App

Clone our example repository and navigate to the Cloudflare integration:

git clone https://github.com/niledatabase/niledatabase
cd niledatabase/examples/integrations/cloudflare/

This example includes:

  • Hono: A lightweight web framework
  • Drizzle: A TypeScript ORM
  • Built-in multi-tenant todo list functionality
3

Configure Hyperdrive

Create a Hyperdrive configuration using your Nile connection string:

npx wrangler hyperdrive create your_config_name \
  --connection-string="postgres://..."

Update your wrangler.toml with the Hyperdrive ID returned from the command above:

[hyperdrive]
id = "your_hyperdrive_id"
4

Deploy

Test your application locally:

npm run dev

Deploy to Cloudflare Workers:

npm run deploy

Your globally accelerated multi-tenant application is now live! 🚀

5

What's Next?

Now that you have your application running, you can:

Example Implementation

Here’s a simple example of how to use Nile with Cloudflare Workers:

import { Hono } from 'hono';
import { drizzle } from 'drizzle-orm/neon-serverless';
import { todos } from './schema';

const app = new Hono();

app.post('/api/todos', async (c) => {
  const { title } = await c.req.json();
  const tenant_id = c.req.header('x-tenant-id');
  
  const db = drizzle(c.env.HYPERDRIVE);
  
  const [todo] = await db.insert(todos)
    .values({ title, tenant_id })
    .returning();
    
  return c.json(todo);
});

export default app;

Was this page helpful?