MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / connectWithTcp

Function connectWithTcp

run/idp-sql/cloud-sql.js:60–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59// Method to connect locally on Windows
60const connectWithTcp = credConfig => {
61 // Extract host and port from socket address
62 const dbSocketAddr = process.env.DB_HOST.split(':'); // e.g. '127.0.0.1:5432'
63 // Establish a connection to the database
64 return Knex({
65 client: 'pg',
66 connection: {
67 user: credConfig.DB_USER, // e.g. 'my-user'
68 password: credConfig.DB_PASSWORD, // e.g. 'my-user-password'
69 database: credConfig.DB_NAME, // e.g. 'my-database'
70 host: dbSocketAddr[0], // e.g. '127.0.0.1'
71 port: dbSocketAddr[1], // e.g. '5432'
72 },
73 ...config,
74 });
75};
76
77/**
78 * Connect to the Cloud SQL instance through TCP or UNIX Sockets

Callers 1

connectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected