terrible latency with simple sql statements.

main.ts
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';
import fs from 'fs';
import { employees } from './schema';
import "dotenv/config"
import { performance } from 'node:perf_hooks';
import { eq } from 'drizzle-orm';

const queryClient = postgres(process.env.DB_URL as string, {
ssl: {
ca: fs.readFileSync(process.env.SSL_ROOT_CERT_PATH as string).toString(),
}
});
const db = drizzle(queryClient);

async function selectAll() {
// const prepared = await db.select().from(employees).prepare("statement_name");
const prepared = await db.select().from(employees).where(eq(employees.firstName, 'John')).prepare("statement_name");
const start = performance.now();
const result = await prepared.execute();
const end = performance.now();
console.log(`Execution time: ${end - start} ms`);
console.log(result);
}

selectAll();
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';
import fs from 'fs';
import { employees } from './schema';
import "dotenv/config"
import { performance } from 'node:perf_hooks';
import { eq } from 'drizzle-orm';

const queryClient = postgres(process.env.DB_URL as string, {
ssl: {
ca: fs.readFileSync(process.env.SSL_ROOT_CERT_PATH as string).toString(),
}
});
const db = drizzle(queryClient);

async function selectAll() {
// const prepared = await db.select().from(employees).prepare("statement_name");
const prepared = await db.select().from(employees).where(eq(employees.firstName, 'John')).prepare("statement_name");
const start = performance.now();
const result = await prepared.execute();
const end = performance.now();
console.log(`Execution time: ${end - start} ms`);
console.log(result);
}

selectAll();
>tsx watch app/db/main.ts The above code results in average of 1200ms latency. I have a simple table with 10 entries of dummy data. However, when I do the same statements but in drizzle studio or psql I get <100ms latency. What am I doing wrong?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server