--ca-certificate-id and --mtls-certificate-id are specified.node-postgres:With node-postgres, you can install pg-native to boost the speed of both node-postgres and Drizzle by approximately 10%.This won't matter on Workers because Workers doesn't support native extensions.
node-postgres supports providing type parsers on a per-query basis without globally patching things. For more details, see Types Docs.Seems valid but probably somewhat of an advanced use-case?
postgres.js uses prepared statements by default, which you may need to opt out of. This could be a potential issue in AWS environments, among others, so please keep that in mind.Hyperdrive fully supports prepared statements now, and they improve performance so this is probably a benefit of
postgres.js actually// Clean up the connectionAlso, AJR explained why this was a good idea a while back, but might be good to add a line claryfing this in the docs because people might generally assume it's bad practice to close connections on every request.
ctx.waitUntil(sql.end());
max set to 5, so just porting that to the new docs would be good 
postgres://USERNAME:PASSWORD@HOSTNAME_OR_IP_ADDRESS:PORT/database_nameAs many hosted databases have limits on the number of unique connections they can manage, Hyperdrive attempts to keep number of concurrent pooled connections to your origin database lower.


Optimized Host: aws.connect.psdb.cloud or Direct which in my case is eu-central.connect.psdb.cloud?ssl={"rejectUnauthorized":true} at the end, should I keep it?import { createConnection } from "mysql2/promise"; whereas kysely says import { createPool } from 'mysql2' // do not use 'mysql2/promises'! (https://www.kysely.dev/docs/getting-started?package-manager=pnpm&dialect=mysql#instantiationconnectionLimit? Default in kysely docs is 10Optimized Host will likely just add a layer of complexity since they'll be trying to also handle global routing.createConnection is correct. Note that because of the way Hyperdrive works, it's safe and recommended to create a new connection on every request (and terminate the connection after each request using ctx.waitUntil).createConnection even has a connectionLimit param because it's not pooling anyway...)MysqlDialect only supports pool connection it seems --ca-certificate-id--mtls-certificate-idnode-postgrespostgres.jspostgres://USERNAME:PASSWORD@HOSTNAME_OR_IP_ADDRESS:PORT/database_nameOptimized HostOptimized Hostaws.connect.psdb.cloudDirecteu-central.connect.psdb.cloud?ssl={"rejectUnauthorized":true}import { createConnection } from "mysql2/promise";import { createPool } from 'mysql2' // do not use 'mysql2/promises'!connectionLimitconnectionLimitcreateConnectioncreateConnectionMysqlDialectpoolname: Deploy App
on:
push:
branches: main
permissions:
contents: read
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install dependencies
run: npm ci
- name: Check DB migrations
run: |
output=$(npx drizzle-kit generate)
echo "$output"
if ! echo "$output" | grep -q "No schema changes, nothing to migrate"; then
echo; echo "Error: Schema changes detected. Please generate migrations before deploying."
exit 1
fi
- name: Apply DB migrations
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: npx drizzle-kit migrate
- name: Deploy application to Cloudflare
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler deployconst connection = await mysql.createConnection({
host: host,
user: username,
password: password,
database: database,
port: port,
disableEval: true,
connectTimeout: 1000,
ssl: {
rejectUnauthorized: true,
}
});app.all("*", async (c, next) => {
const sql = postgres(c.env.database.connectionString, {
max: 5,
fetch_types: false
});
const db = drizzle(sql);
c.set("database", db);
await next()
})c.executionCtx.waitUntil(sql.end())