Google cloud postgres

I am having trouble using drizzle-kit to connect to my google cloud sql instance. I can connect just fine with @google-cloud/cloud-sql-connector but i'm not sure how to run drizzle-kit as the DATABASE_URL string is not enough.
npx drizzle-kit push
drizzle-kit: v0.23.0
drizzle-orm: v0.32.0

No config path provided, using default path
Reading config file '.../drizzle.config.ts'
Using 'pg' driver for database querying

Error: connect ETIMEDOUT ...:5432
at .../node_modules/drizzle-kit/bin.cjs:79476:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (.../node_modules/drizzle-kit/bin.cjs:121418:26)
at async fromDatabase2 (.../node_modules/drizzle-kit/bin.cjs:21810:25) {
errno: -60,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '...',
port: 5432
}
npx drizzle-kit push
drizzle-kit: v0.23.0
drizzle-orm: v0.32.0

No config path provided, using default path
Reading config file '.../drizzle.config.ts'
Using 'pg' driver for database querying

Error: connect ETIMEDOUT ...:5432
at .../node_modules/drizzle-kit/bin.cjs:79476:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.query (.../node_modules/drizzle-kit/bin.cjs:121418:26)
at async fromDatabase2 (.../node_modules/drizzle-kit/bin.cjs:21810:25) {
errno: -60,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '...',
port: 5432
}
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: './lib/db.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL,
},
verbose: true,
strict: true,
});
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: './lib/db.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL,
},
verbose: true,
strict: true,
});
import { Connector, IpAddressTypes } from '@google-cloud/cloud-sql-connector';
import { relations } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

const connector = new Connector();

export async function connect() {
const clientOpts = await connector.getOptions({
instanceConnectionName: process.env.CLOUD_SQL_CONNECTION_NAME,
ipType: IpAddressTypes.PUBLIC,
});
const pool = new Pool({
...clientOpts,
connectionString: process.env.DATABASE_URL,
max: 5,
});
await pool.connect();

const { rows } = await pool.query('SELECT NOW()');
console.table(rows);
return drizzle(pool);
}
import { Connector, IpAddressTypes } from '@google-cloud/cloud-sql-connector';
import { relations } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

const connector = new Connector();

export async function connect() {
const clientOpts = await connector.getOptions({
instanceConnectionName: process.env.CLOUD_SQL_CONNECTION_NAME,
ipType: IpAddressTypes.PUBLIC,
});
const pool = new Pool({
...clientOpts,
connectionString: process.env.DATABASE_URL,
max: 5,
});
await pool.connect();

const { rows } = await pool.query('SELECT NOW()');
console.table(rows);
return drizzle(pool);
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server