Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPC-8383: Upgrade knex to latest version #258

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"lint": "yarn lint-prettier && yarn lint-eslint"
},
"dependencies": {
"@unocha/hpc-api-core": "^8.2.0",
"@unocha/hpc-api-core": "^9.0.0",
"apollo-server-hapi": "^3.12.0",
"bunyan": "^1.8.15",
"class-validator": "^0.14.1",
"graphql": "^15.7.2",
"knex": "0.21.1",
"pg": "^8.11.3",
"knex": "3.1.0",
"pg": "^8.12.0",
"pm2": "^5.4.2",
"reflect-metadata": "^0.2.2",
"ts-node": "^10.9.2",
Expand All @@ -37,7 +37,7 @@
"@types/hapi__hapi": "^20.0.9",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.1",
"@types/pg": "^8.11.3",
"@types/pg": "^8.11.6",
"@unocha/hpc-repo-tools": "^4.2.0",
"eslint": "^8.57.0",
"husky": "^9.1.5",
Expand Down
8 changes: 4 additions & 4 deletions src/data-providers/postgres/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Knex from 'knex';
import { knex } from 'knex';
import { CONFIG } from '../../../config';

/**
* Initialize a new Postgres provider
*/
export async function createDbConnection() {
const knex = Knex({
const knexInstance = knex({
client: 'pg',
connection: CONFIG.db.connection,
pool: {
Expand All @@ -18,9 +18,9 @@ export async function createDbConnection() {

// Verify the connection before proceeding
try {
await knex.raw('SELECT now()');
await knexInstance.raw('SELECT now()');

return knex;
return knexInstance;
} catch {
throw new Error(
'Unable to connect to Postgres via Knex. Ensure a valid connection.'
Expand Down
5 changes: 2 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as Hapi from '@hapi/hapi';
import v4Models from '@unocha/hpc-api-core/src/db';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import {
ApolloServer,
ApolloServerPluginStopHapiServer,
} from 'apollo-server-hapi';
import { type Knex } from 'knex';
import path from 'node:path';
import 'reflect-metadata';
import { buildSchema } from 'type-graphql';
import { Container } from 'typedi';
import Knex = require('knex');

import v4Models from '@unocha/hpc-api-core/src/db';
import { CONFIG } from '../config';
import { getTokenFromRequest } from './common-libs/auth';
import { initializeLogging } from './common-libs/logging';
Expand Down
2 changes: 1 addition & 1 deletion tests/testContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import v4Models, { type Database } from '@unocha/hpc-api-core/src/db';
import { type ApolloServer } from 'apollo-server-hapi';
import type Knex from 'knex';
import type { Knex } from 'knex';
import { createDbConnection } from './utils/connection';
import createApolloTestServer from './utils/server';

Expand Down
8 changes: 4 additions & 4 deletions tests/utils/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as t from 'io-ts';
import Knex from 'knex';
import { knex } from 'knex';

const CONFIG = t.type({
host: t.string,
Expand All @@ -12,7 +12,7 @@ const CONFIG = t.type({
* Initialize a new Postgres provider
*/
export async function createDbConnection(connection: t.TypeOf<typeof CONFIG>) {
const knex = Knex({
const knexInstance = knex({
client: 'pg',
connection,
pool: { min: 0, max: 10, idleTimeoutMillis: 500 },
Expand All @@ -21,9 +21,9 @@ export async function createDbConnection(connection: t.TypeOf<typeof CONFIG>) {

// Verify the connection before proceeding
try {
await knex.raw('SELECT now()');
await knexInstance.raw('SELECT now()');

return knex;
return knexInstance;
} catch (error) {
console.log(error);
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ApolloServer,
ApolloServerPluginStopHapiServer,
} from 'apollo-server-hapi';
import type Knex from 'knex';
import type { Knex } from 'knex';
import path from 'node:path';
import 'reflect-metadata';
import { buildSchema } from 'type-graphql';
Expand Down
Loading
Loading