Skip to content

Commit

Permalink
chore: fix database name on knex examples (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno authored Nov 24, 2023
1 parent fabe9b6 commit 9cf07a3
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/knex/mysql2/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function connect({ instanceConnectionName, user, databaseName }) {
connection: {
...clientOpts,
user,
databaseName,
database: databaseName,
},
});

Expand Down
4 changes: 2 additions & 2 deletions examples/knex/mysql2/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {Connector} from '@google-cloud/cloud-sql-connector';
import knex from 'knex';

export async function connect({ instanceConnectionName, user, db }) {
export async function connect({ instanceConnectionName, user, databaseName }) {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName,
Expand All @@ -28,7 +28,7 @@ export async function connect({ instanceConnectionName, user, db }) {
connection: {
...clientOpts,
user,
db,
database: databaseName,
},
});

Expand Down
4 changes: 2 additions & 2 deletions examples/knex/mysql2/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@google-cloud/cloud-sql-connector';
import knex from 'knex';

export async function connect({instanceConnectionName, user, db}) {
export async function connect({instanceConnectionName, user, databaseName}) {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName,
Expand All @@ -32,7 +32,7 @@ export async function connect({instanceConnectionName, user, db}) {
connection: {
...clientOpts,
user,
db,
database: databaseName,
},
});

Expand Down
2 changes: 1 addition & 1 deletion examples/knex/mysql2/test/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('mysql knex cjs', async t => {
const {database, close} = await connect({
instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME,
user: process.env.MYSQL_IAM_USER,
db: process.env.MYSQL_DB,
databaseName: process.env.MYSQL_DB,
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/mysql2/test/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('mysql knex mjs', async t => {
const {database, close} = await connect({
instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME,
user: process.env.MYSQL_IAM_USER,
db: process.env.MYSQL_DB,
databaseName: process.env.MYSQL_DB,
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/mysql2/test/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('mysql knex ts', async t => {
const {database, close} = await connect({
instanceConnectionName: process.env.MYSQL_IAM_CONNECTION_NAME,
user: process.env.MYSQL_IAM_USER,
db: process.env.MYSQL_DB,
databaseName: process.env.MYSQL_DB,
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
4 changes: 2 additions & 2 deletions examples/knex/pg/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const {Connector} = require('@google-cloud/cloud-sql-connector');
const knex = require('knex');

async function connect({ instanceConnectionName, user, db }) {
async function connect({ instanceConnectionName, user, databaseName }) {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName,
Expand All @@ -28,7 +28,7 @@ async function connect({ instanceConnectionName, user, db }) {
connection: {
...clientOpts,
user,
database: db,
database: databaseName,
},
});

Expand Down
4 changes: 2 additions & 2 deletions examples/knex/pg/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {Connector} from '@google-cloud/cloud-sql-connector';
import knex from 'knex';

export async function connect({ instanceConnectionName, user, db }) {
export async function connect({ instanceConnectionName, user, databaseName }) {
const connector = new Connector();
const clientOpts = await connector.getOptions({
instanceConnectionName,
Expand All @@ -28,7 +28,7 @@ export async function connect({ instanceConnectionName, user, db }) {
connection: {
...clientOpts,
user,
database: db,
database: databaseName,
},
});

Expand Down
6 changes: 3 additions & 3 deletions examples/knex/pg/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import knex from 'knex';
export async function connect({
instanceConnectionName,
user,
db,
databaseName,
}: {
instanceConnectionName: string;
user: string;
db: string;
databaseName: string;
}) {
const connector = new Connector();
const clientOpts = await connector.getOptions({
Expand All @@ -40,7 +40,7 @@ export async function connect({
connection: {
...clientOpts,
user,
database: db,
database: databaseName,
},
});

Expand Down
2 changes: 1 addition & 1 deletion examples/knex/pg/test/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('pg knex cjs', async t => {
const {database, close} = await connect({
instanceConnectionName: process.env.POSTGRES_IAM_CONNECTION_NAME,
user: process.env.POSTGRES_IAM_USER,
db: process.env.POSTGRES_DB,
databaseName: process.env.POSTGRES_DB,
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/pg/test/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('pg knex mjs', async t => {
const {database, close} = await connect({
instanceConnectionName: process.env.POSTGRES_IAM_CONNECTION_NAME,
user: process.env.POSTGRES_IAM_USER,
db: process.env.POSTGRES_DB,
databaseName: process.env.POSTGRES_DB,
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/pg/test/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ t.test('pg knex ts', async t => {
const {database, close} = await connect({
instanceConnectionName: String(process.env.POSTGRES_IAM_CONNECTION_NAME),
user: String(process.env.POSTGRES_IAM_USER),
db: String(process.env.POSTGRES_DB),
databaseName: String(process.env.POSTGRES_DB),
});
const {now} = await database.first(database.raw('NOW() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
4 changes: 2 additions & 2 deletions examples/knex/tedious/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const {Connector} = require('@google-cloud/cloud-sql-connector');
const knex = require('knex');

async function connect({ instanceConnectionName, user, password, db }) {
async function connect({ instanceConnectionName, user, password, databaseName }) {
const connector = new Connector();
const clientOpts = await connector.getTediousOptions({
instanceConnectionName,
Expand All @@ -33,7 +33,7 @@ async function connect({ instanceConnectionName, user, password, db }) {
server: '0.0.0.0',
user,
password,
database: db,
database: databaseName,
options: {
...clientOpts,
},
Expand Down
4 changes: 2 additions & 2 deletions examples/knex/tedious/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {Connector} from '@google-cloud/cloud-sql-connector';
import knex from 'knex';

export async function connect({ instanceConnectionName, user, password, db }) {
export async function connect({ instanceConnectionName, user, password, databaseName }) {
const connector = new Connector();
const clientOpts = await connector.getTediousOptions({
instanceConnectionName,
Expand All @@ -33,7 +33,7 @@ export async function connect({ instanceConnectionName, user, password, db }) {
server: '0.0.0.0',
user,
password,
database: db,
database: databaseName,
options: {
...clientOpts,
},
Expand Down
9 changes: 7 additions & 2 deletions examples/knex/tedious/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
} from '@google-cloud/cloud-sql-connector';
import knex from 'knex';

export async function connect({instanceConnectionName, user, password, db}) {
export async function connect({
instanceConnectionName,
user,
password,
databaseName,
}) {
const connector = new Connector();
const clientOpts = await connector.getTediousOptions({
instanceConnectionName,
Expand All @@ -37,7 +42,7 @@ export async function connect({instanceConnectionName, user, password, db}) {
server: '0.0.0.0',
user,
password,
database: db,
database: databaseName,
options: {
...clientOpts,
},
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/tedious/test/connect.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('tedious knex cjs', async t => {
instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME,
user: process.env.SQLSERVER_USER,
password: process.env.SQLSERVER_PASS,
database: process.env.SQLSERVER_DB,
databaseName: process.env.SQLSERVER_DB,
});
const {now} = await database.first(database.raw('GETUTCDATE() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/tedious/test/connect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('tedious knex mjs', async t => {
instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME,
user: process.env.SQLSERVER_USER,
password: process.env.SQLSERVER_PASS,
database: process.env.SQLSERVER_DB,
databaseName: process.env.SQLSERVER_DB,
});
const {now} = await database.first(database.raw('GETUTCDATE() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down
2 changes: 1 addition & 1 deletion examples/knex/tedious/test/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('tedious knex ts', async t => {
instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME,
user: process.env.SQLSERVER_USER,
password: process.env.SQLSERVER_PASS,
database: process.env.SQLSERVER_DB,
databaseName: process.env.SQLSERVER_DB,
});
const {now} = await database.first(database.raw('GETUTCDATE() AS now'));
t.ok(now.getTime(), 'should have valid returned date object');
Expand Down

0 comments on commit 9cf07a3

Please sign in to comment.