Skip to content

Commit 33da62b

Browse files
committed
chore: rename connection functions
1 parent 933e3b8 commit 33da62b

10 files changed

Lines changed: 72 additions & 72 deletions

File tree

examples/cloudrun/knex/mysql2/index.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getIpType(ipTypeStr) {
5252
}
5353

5454
// Function to create a database connection pool using IAM authentication
55-
async function getIamConnection() {
55+
async function createIamConnectionPool() {
5656
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
5757
// IAM service account email
5858
const dbUser = process.env.DB_IAM_USER;
@@ -83,7 +83,7 @@ async function getIamConnection() {
8383
}
8484

8585
// Function to create a database connection pool using password authentication
86-
async function getPasswordConnection() {
86+
async function createPasswordConnectionPool() {
8787
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
8888
// Database username
8989
const dbUser = process.env.DB_USER;
@@ -115,24 +115,24 @@ async function getPasswordConnection() {
115115
}
116116

117117
// Helper to get or create the password pool
118-
async function getConnectionSettings() {
118+
async function getPasswordConnectionPool() {
119119
if (!passwordPool) {
120-
passwordPool = await getPasswordConnection();
120+
passwordPool = await createPasswordConnectionPool();
121121
}
122122
return passwordPool;
123123
}
124124

125125
// Helper to get or create the IAM pool
126-
async function getIamConnectionSettings() {
126+
async function getIamConnectionPool() {
127127
if (!iamPool) {
128-
iamPool = await getIamConnection();
128+
iamPool = await createIamConnectionPool();
129129
}
130130
return iamPool;
131131
}
132132

133133
app.get('/', async (req, res) => {
134134
try {
135-
const db = await getConnectionSettings();
135+
const db = await getPasswordConnectionPool();
136136
// Use knex to run a simple query
137137
const result = await db.raw('SELECT 1');
138138
// Knex raw result for mysql2 is [rows, fields]
@@ -145,7 +145,7 @@ app.get('/', async (req, res) => {
145145

146146
app.get('/iam', async (req, res) => {
147147
try {
148-
const db = await getIamConnectionSettings();
148+
const db = await getIamConnectionPool();
149149
const result = await db.raw('SELECT 1');
150150
res.send(`Database connection successful (IAM authentication), result: ${JSON.stringify(result[0])}`);
151151
} catch (err) {

examples/cloudrun/knex/pg/index.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getIpType(ipTypeStr) {
5252
}
5353

5454
// Function to create a database connection pool using IAM authentication
55-
async function getIamConnection() {
55+
async function createIamConnectionPool() {
5656
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
5757
// IAM service account email
5858
const dbUser = process.env.DB_IAM_USER;
@@ -83,7 +83,7 @@ async function getIamConnection() {
8383
}
8484

8585
// Function to create a database connection pool using password authentication
86-
async function getPasswordConnection() {
86+
async function createPasswordConnectionPool() {
8787
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
8888
// Database username
8989
const dbUser = process.env.DB_USER;
@@ -115,24 +115,24 @@ async function getPasswordConnection() {
115115
}
116116

117117
// Helper to get or create the password pool
118-
async function getConnectionSettings() {
118+
async function getPasswordConnectionPool() {
119119
if (!passwordPool) {
120-
passwordPool = await getPasswordConnection();
120+
passwordPool = await createPasswordConnectionPool();
121121
}
122122
return passwordPool;
123123
}
124124

125125
// Helper to get or create the IAM pool
126-
async function getIamConnectionSettings() {
126+
async function getIamConnectionPool() {
127127
if (!iamPool) {
128-
iamPool = await getIamConnection();
128+
iamPool = await createIamConnectionPool();
129129
}
130130
return iamPool;
131131
}
132132

133133
app.get('/', async (req, res) => {
134134
try {
135-
const db = await getConnectionSettings();
135+
const db = await getPasswordConnectionPool();
136136
const result = await db.raw('SELECT 1');
137137
res.send(`Database connection successful (password authentication), result: ${JSON.stringify(result.rows)}`);
138138
} catch (err) {
@@ -143,7 +143,7 @@ app.get('/', async (req, res) => {
143143

144144
app.get('/iam', async (req, res) => {
145145
try {
146-
const db = await getIamConnectionSettings();
146+
const db = await getIamConnectionPool();
147147
const result = await db.raw('SELECT 1');
148148
res.send(`Database connection successful (IAM authentication), result: ${JSON.stringify(result.rows)}`);
149149
} catch (err) {

examples/cloudrun/prisma/mysql/index.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function getIpType(ipTypeStr) {
5555
}
5656

5757
// Function to create a database connection pool using IAM authentication
58-
async function getIamConnection() {
58+
async function createIamConnectionPool() {
5959
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
6060
// IAM service account email
6161
const dbUser = process.env.DB_IAM_USER;
@@ -94,7 +94,7 @@ async function getIamConnection() {
9494
}
9595

9696
// Function to create a database connection pool using password authentication
97-
async function getPasswordConnection() {
97+
async function createPasswordConnectionPool() {
9898
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
9999
// Database username
100100
const dbUser = process.env.DB_USER;
@@ -133,19 +133,19 @@ async function getPasswordConnection() {
133133
}
134134

135135
// Helper to get or create the password pool
136-
async function getConnectionSettings() {
136+
async function getPasswordConnectionPool() {
137137
if (!passwordClient) {
138-
const { prisma, close } = await getPasswordConnection();
138+
const { prisma, close } = await createPasswordConnectionPool();
139139
passwordClient = prisma;
140140
passwordCleanup = close;
141141
}
142142
return passwordClient;
143143
}
144144

145145
// Helper to get or create the IAM pool
146-
async function getIamConnectionSettings() {
146+
async function getIamConnectionPool() {
147147
if (!iamClient) {
148-
const { prisma, close } = await getIamConnection();
148+
const { prisma, close } = await createIamConnectionPool();
149149
iamClient = prisma;
150150
iamCleanup = close;
151151
}
@@ -154,7 +154,7 @@ async function getIamConnectionSettings() {
154154

155155
app.get('/', async (req, res) => {
156156
try {
157-
const prisma = await getConnectionSettings();
157+
const prisma = await getPasswordConnectionPool();
158158
const result = await prisma.$queryRaw`SELECT 1`;
159159
const serialized = JSON.stringify(result, (key, value) =>
160160
typeof value === 'bigint' ? value.toString() : value
@@ -168,7 +168,7 @@ app.get('/', async (req, res) => {
168168

169169
app.get('/iam', async (req, res) => {
170170
try {
171-
const prisma = await getIamConnectionSettings();
171+
const prisma = await getIamConnectionPool();
172172
const result = await prisma.$queryRaw`SELECT 1`;
173173
const serialized = JSON.stringify(result, (key, value) =>
174174
typeof value === 'bigint' ? value.toString() : value

examples/cloudrun/prisma/postgresql/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function getIpType(ipTypeStr: string | undefined) {
6060
}
6161

6262
// Function to create a database connection pool using IAM authentication
63-
async function getIamConnection() {
63+
async function createIamConnectionPool() {
6464
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME || '';
6565
// IAM service account email
6666
const dbUser = process.env.DB_IAM_USER || '';
@@ -104,7 +104,7 @@ async function getIamConnection() {
104104
}
105105

106106
// Function to create a database connection pool using password authentication
107-
async function getPasswordConnection() {
107+
async function createPasswordConnectionPool() {
108108
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME || '';
109109
// Database username
110110
const dbUser = process.env.DB_USER || '';
@@ -147,19 +147,19 @@ async function getPasswordConnection() {
147147
}
148148

149149
// Helper to get or create the password pool
150-
async function getConnectionSettings() {
150+
async function getPasswordConnectionPool() {
151151
if (!passwordClient) {
152-
const {prisma, close} = await getPasswordConnection();
152+
const {prisma, close} = await createPasswordConnectionPool();
153153
passwordClient = prisma;
154154
passwordCleanup = close;
155155
}
156156
return passwordClient;
157157
}
158158

159159
// Helper to get or create the IAM pool
160-
async function getIamConnectionSettings() {
160+
async function getIamConnectionPool() {
161161
if (!iamClient) {
162-
const {prisma, close} = await getIamConnection();
162+
const {prisma, close} = await createIamConnectionPool();
163163
iamClient = prisma;
164164
iamCleanup = close;
165165
}
@@ -168,7 +168,7 @@ async function getIamConnectionSettings() {
168168

169169
app.get('/', async (req, res) => {
170170
try {
171-
const prisma = await getConnectionSettings();
171+
const prisma = await getPasswordConnectionPool();
172172
const result = await prisma.$queryRaw`SELECT 1`;
173173
const serialized = JSON.stringify(result, (key, value) =>
174174
typeof value === 'bigint' ? value.toString() : value
@@ -190,7 +190,7 @@ app.get('/', async (req, res) => {
190190

191191
app.get('/iam', async (req, res) => {
192192
try {
193-
const prisma = await getIamConnectionSettings();
193+
const prisma = await getIamConnectionPool();
194194
const result = await prisma.$queryRaw`SELECT 1`;
195195
const serialized = JSON.stringify(result, (key, value) =>
196196
typeof value === 'bigint' ? value.toString() : value

examples/cloudrun/sequelize/mysql2/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function getIpType(ipTypeStr: string | undefined) {
5656
}
5757

5858
// Function to create a database connection pool using IAM authentication
59-
async function getIamConnection() {
59+
async function createIamConnectionPool() {
6060
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME || '';
6161
// IAM service account email
6262
const dbUser = process.env.DB_IAM_USER || '';
@@ -88,7 +88,7 @@ async function getIamConnection() {
8888
}
8989

9090
// Function to create a database connection pool using password authentication
91-
async function getPasswordConnection() {
91+
async function createPasswordConnectionPool() {
9292
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME || '';
9393
// Database username
9494
const dbUser = process.env.DB_USER || '';
@@ -122,24 +122,24 @@ async function getPasswordConnection() {
122122
}
123123

124124
// Helper to get or create the password pool
125-
async function getConnectionSettings() {
125+
async function getPasswordConnectionPool() {
126126
if (!passwordPool) {
127-
passwordPool = await getPasswordConnection();
127+
passwordPool = await createPasswordConnectionPool();
128128
}
129129
return passwordPool;
130130
}
131131

132132
// Helper to get or create the IAM pool
133-
async function getIamConnectionSettings() {
133+
async function getIamConnectionPool() {
134134
if (!iamPool) {
135-
iamPool = await getIamConnection();
135+
iamPool = await createIamConnectionPool();
136136
}
137137
return iamPool;
138138
}
139139

140140
app.get('/', async (req, res) => {
141141
try {
142-
const db = await getConnectionSettings();
142+
const db = await getPasswordConnectionPool();
143143
await db.authenticate();
144144
const [results] = await db.query('SELECT 1');
145145
res.send(
@@ -159,7 +159,7 @@ app.get('/', async (req, res) => {
159159

160160
app.get('/iam', async (req, res) => {
161161
try {
162-
const db = await getIamConnectionSettings();
162+
const db = await getIamConnectionPool();
163163
await db.authenticate();
164164
const [results] = await db.query('SELECT 1');
165165
res.send(

examples/cloudrun/sequelize/pg/index.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getIpType(ipTypeStr) {
5252
}
5353

5454
// Function to create a database connection pool using IAM authentication
55-
async function getIamConnection() {
55+
async function createIamConnectionPool() {
5656
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
5757
// IAM service account email
5858
const dbUser = process.env.DB_IAM_USER;
@@ -81,7 +81,7 @@ async function getIamConnection() {
8181
}
8282

8383
// Function to create a database connection pool using password authentication
84-
async function getPasswordConnection() {
84+
async function createPasswordConnectionPool() {
8585
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
8686
// Database username
8787
const dbUser = process.env.DB_USER;
@@ -111,24 +111,24 @@ async function getPasswordConnection() {
111111
}
112112

113113
// Helper to get or create the password pool
114-
async function getConnectionSettings() {
114+
async function getPasswordConnectionPool() {
115115
if (!passwordPool) {
116-
passwordPool = await getPasswordConnection();
116+
passwordPool = await createPasswordConnectionPool();
117117
}
118118
return passwordPool;
119119
}
120120

121121
// Helper to get or create the IAM pool
122-
async function getIamConnectionSettings() {
122+
async function getIamConnectionPool() {
123123
if (!iamPool) {
124-
iamPool = await getIamConnection();
124+
iamPool = await createIamConnectionPool();
125125
}
126126
return iamPool;
127127
}
128128

129129
app.get('/', async (req, res) => {
130130
try {
131-
const db = await getConnectionSettings();
131+
const db = await getPasswordConnectionPool();
132132
await db.authenticate();
133133
const [results, metadata] = await db.query('SELECT 1');
134134
res.send(`Database connection successful (password authentication), result: ${JSON.stringify(results)}`);
@@ -140,7 +140,7 @@ app.get('/', async (req, res) => {
140140

141141
app.get('/iam', async (req, res) => {
142142
try {
143-
const db = await getIamConnectionSettings();
143+
const db = await getIamConnectionPool();
144144
await db.authenticate();
145145
const [results, metadata] = await db.query('SELECT 1');
146146
res.send(`Database connection successful (IAM authentication), result: ${JSON.stringify(results)}`);

examples/cloudrun/sequelize/tedious/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function getIpType(ipTypeStr) {
5151
}
5252

5353
// Function to create a database connection pool using password authentication
54-
async function getPasswordConnection() {
54+
async function createPasswordConnectionPool() {
5555
const instanceConnectionName = process.env.INSTANCE_CONNECTION_NAME;
5656
// Database username
5757
const dbUser = process.env.DB_USER;
@@ -87,16 +87,16 @@ async function getPasswordConnection() {
8787
}
8888

8989
// Helper to get or create the password pool
90-
async function getConnectionSettings() {
90+
async function getPasswordConnectionPool() {
9191
if (!passwordPool) {
92-
passwordPool = await getPasswordConnection();
92+
passwordPool = await createPasswordConnectionPool();
9393
}
9494
return passwordPool;
9595
}
9696

9797
app.get('/', async (req, res) => {
9898
try {
99-
const db = await getConnectionSettings();
99+
const db = await getPasswordConnectionPool();
100100
await db.authenticate();
101101
const [results, metadata] = await db.query('SELECT 1');
102102
res.send(`Database connection successful (password authentication), result: ${JSON.stringify(results)}`);

0 commit comments

Comments
 (0)