Cloudflare
Hyperdrive
Use Cloudflare Hyperdrive for accelerated database connections in your Vela application.
The HyperdriveModule provides a managed HyperdriveService that exposes accelerated connection details for your database through Cloudflare Hyperdrive.
Setup
Import the module and configure the binding name:
import { Module } from '@velajs/vela';
import { HyperdriveModule } from '@velajs/cloudflare';
@Module({
imports: [HyperdriveModule.forRoot({ binding: 'MY_HYPERDRIVE' })],
})
class AppModule {}Add the Hyperdrive binding to wrangler.toml:
[[hyperdrive]]
binding = "MY_HYPERDRIVE"
id = "xxx"Using HyperdriveService
Inject HyperdriveService to access the accelerated connection parameters:
import { Controller, Get } from '@velajs/vela';
import { HyperdriveService } from '@velajs/cloudflare';
import { Client } from 'pg';
@Controller('db')
class DbController {
constructor(private readonly hyperdrive: HyperdriveService) {}
@Get('status')
async status() {
const client = new Client({
connectionString: this.hyperdrive.connectionString,
});
await client.connect();
const result = await client.query('SELECT NOW()');
await client.end();
return { time: result.rows[0].now };
}
}Properties
| Property | Description |
|---|---|
connectionString | Full connection string for the accelerated database connection. |
host | Hyperdrive proxy hostname. |
port | Hyperdrive proxy port. |
user | Database username. |
password | Database password. |
database | Database name. |
Vectorize
Use Cloudflare Vectorize for vector search in your Vela application.
Scheduled Events
Handle cron triggers in Cloudflare Workers.
Edit on GitHub
Last updated on