From ea8f1bc5f6745e374a4b33142d08ff4e2bf9beee Mon Sep 17 00:00:00 2001 From: Dosun Yun Date: Wed, 9 Nov 2022 07:09:06 +0900 Subject: [PATCH] [BE-setup] Remove IBM Db2 --- backend-api/Dockerfile | 26 +-- backend-api/package.json | 1 - .../connection/knex-dialects/ibm-db/index.js | 160 +++++++++++++++++ .../knex-dialects/ibm-db/transaction.ts | 17 ++ .../connection/knex-dialects/knex-ibm-db.ts | 168 +++++++++--------- 5 files changed, 268 insertions(+), 104 deletions(-) create mode 100644 backend-api/src/connection/knex-dialects/ibm-db/index.js create mode 100644 backend-api/src/connection/knex-dialects/ibm-db/transaction.ts diff --git a/backend-api/Dockerfile b/backend-api/Dockerfile index 5ec5bb5..9936897 100644 --- a/backend-api/Dockerfile +++ b/backend-api/Dockerfile @@ -1,19 +1,3 @@ -# STEP 1 NPM Build -FROM node:14 AS builder -# ORACLE 설치 -RUN apt-get update && apt-get install -y libaio1 wget unzip -WORKDIR /opt/oracle -RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \ - unzip instantclient-basiclite-linuxx64.zip && rm -f instantclient-basiclite-linuxx64.zip && \ - cd /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *mql1* *ipc1* *jar uidrvci genezi adrci && \ - echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig -#NODE Build -WORKDIR /app -COPY . . -RUN yarn -RUN yarn build - -# STEP 2 Running Env FROM node:14-slim # ORACLE 설치 RUN apt-get update && apt-get install -y libaio1 wget unzip @@ -23,6 +7,10 @@ RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantcli cd /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *mql1* *ipc1* *jar uidrvci genezi adrci && \ echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig WORKDIR /app -ENV NODE_ENV production -COPY --from=builder /app ./ -CMD ["yarn","start:prod"] \ No newline at end of file +# ENV NODE_ENV production +# COPY --from=builder /app ./ +COPY . . +RUN npm install +RUN npm run build + +CMD ["npm","run","start:prod"] \ No newline at end of file diff --git a/backend-api/package.json b/backend-api/package.json index d06276b..fa88aca 100644 --- a/backend-api/package.json +++ b/backend-api/package.json @@ -45,7 +45,6 @@ "cookie-parser": "^1.4.5", "cross-env": "^7.0.3", "dylib-node": "^1.0.10", - "ibm_db": "^3.0.0", "js-joda": "^1.11.0", "knex": "^2.3.0", "knex-bigquery": "^2.0.3", diff --git a/backend-api/src/connection/knex-dialects/ibm-db/index.js b/backend-api/src/connection/knex-dialects/ibm-db/index.js new file mode 100644 index 0000000..a619ea9 --- /dev/null +++ b/backend-api/src/connection/knex-dialects/ibm-db/index.js @@ -0,0 +1,160 @@ +// import { Knex, knex } from 'knex'; +// import { Database } from 'ibm_db'; +// import Client = knex.Client; + +// const Promise = require('bluebird'); +// const Client = require('knex/lib/client'); +// +// class DB2Client extends Client { +// constructor(config) { +// super(config); +// } +// +// get dialect() { +// return 'ibm_db'; +// } +// +// get driverName() { +// return 'ibm_db'; +// } +// +// get canCancelQuery() { +// return true; +// } +// +// _driver() { +// return Promise.promisifyAll(require(this.driverName)); +// } +// +// // transaction() { +// // return new Transaction(this, ...arguments); +// // } +// +// wrapIdentifierImpl(value) { +// // override default wrapper ("). we don't want to use it since +// // it makes identifiers case-sensitive in DB2 +// return value; +// } +// +// // printDebug(message) { +// // if (process.env.DEBUG === 1) { +// // this.logger.log(message); +// // } +// // } +// +// // Get a raw connection, called by the pool manager whenever a new +// // connection needs to be added to the pool. +// acquireRawConnection() { +// // this.printDebug('acquiring raw connection.'); +// const connectionConfig = this.config.connection; +// return new Promise((resolve, reject) => { +// this.driver.open(this._getConnectionString(connectionConfig), (err, connection) => { +// if (err) { +// return reject(err); +// } +// +// return resolve(connection); +// }); +// }); +// } +// +// // Used to explicitly close a connection, called internally by the pool manager +// // when a connection times out or the pool is shutdown. +// destroyRawConnection(connection) { +// // this.printDebug('destroying raw connection'); +// +// return connection.closeAsync(); +// } +// +// validateConnection(connection) { +// return Promise.resolve(connection.connected); +// } +// +// _stream(connection, obj, stream, options) { +// this._stream(connection, obj, stream, options); +// throw new Error('Not yet implemented'); +// } +// +// _getConnectionString(connectionConfig = {}) { +// const connectionStringParams = connectionConfig.connectionStringParams || {}; +// const connectionStringExtension = Object.keys(connectionStringParams).reduce((result, key) => { +// const value = connectionStringParams[key]; +// return `${result}${key}=${value};`; +// }, ''); +// +// const connectionString = `${ +// `DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};` + +// `PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};` + +// `UID=${connectionConfig.user};PWD=${connectionConfig.password};` +// }${connectionStringExtension}`; +// +// return connectionString; +// } +// +// // Runs the query on the specified connection, providing the bindings +// // and any other necessary prep work. +// _query(connection, obj) { +// // TODO: verify correctness +// if (!obj || typeof obj === 'string') obj = { sql: obj }; +// +// const method = (obj.method !== 'raw' ? obj.method : obj.sql.split(' ')[0]).toLowerCase(); +// +// obj.sqlMethod = method; +// +// // Different functions are used since query() doesn't return # of rows affected, +// // which is needed for queries that modify the database +// if (method === 'select' || method === 'first' || method === 'pluck') { +// return connection.queryAsync(obj.sql, obj.bindings).then(rows => { +// obj.response = { +// rows, +// rowCount: rows.length, +// }; +// +// return obj; +// }); +// } +// +// return connection +// .prepareAsync(obj.sql) +// .then(statement => statement.executeNonQueryAsync(obj.bindings)) +// .then(numRowsAffected => { +// obj.response = { +// rowCount: numRowsAffected, +// }; +// +// return obj; +// }); +// } +// +// // Process / normalize the response as returned from the query +// processResponse(obj, runner) { +// // TODO: verify correctness +// +// if (obj === null) return null; +// +// const resp = obj.response; +// const method = obj.sqlMethod; +// const { rows } = resp; +// +// if (obj.output) return obj.output.call(runner, resp); +// +// switch (method) { +// case 'select': +// case 'pluck': +// case 'first': { +// if (method === 'pluck') return rows.map(obj.pluck); +// return method === 'first' ? rows[0] : rows; +// } +// case 'insert': +// case 'del': +// case 'delete': +// case 'update': +// case 'counter': +// return resp.rowCount; +// default: +// return resp; +// } +// } +// } +// +// module.exports = { DB2Client }; diff --git a/backend-api/src/connection/knex-dialects/ibm-db/transaction.ts b/backend-api/src/connection/knex-dialects/ibm-db/transaction.ts new file mode 100644 index 0000000..b99c704 --- /dev/null +++ b/backend-api/src/connection/knex-dialects/ibm-db/transaction.ts @@ -0,0 +1,17 @@ +// import Transaction from 'knex/lib/execution/transaction'; +// +// class TransactionDb2 extends Transaction { +// begin(conn) { +// return conn.beginTransactionAsync().then(this._resolver).catch(this._rejecter); +// } +// +// commit(conn, value) { +// this._completed = true; +// return conn +// .commitTransactionAsync() +// .then(() => this._resolver(value)) +// .catch(this._rejecter); +// } +// } +// +// module.exports = TransactionDb2; diff --git a/backend-api/src/connection/knex-dialects/knex-ibm-db.ts b/backend-api/src/connection/knex-dialects/knex-ibm-db.ts index f1300f3..402c0ee 100644 --- a/backend-api/src/connection/knex-dialects/knex-ibm-db.ts +++ b/backend-api/src/connection/knex-dialects/knex-ibm-db.ts @@ -1,84 +1,84 @@ -// import Client from "knex/lib/client"; - -import { Knex, knex } from 'knex'; -import { Database } from 'ibm_db'; -import Client = knex.Client; - -export class IbmDbClient extends Client { - constructor(config) { - super(config); - this.dialect = 'ibm_db'; - this.driverName = 'ibm_db'; - this.canCancelQuery = true; - } - - _driver() { - return new Database(); - } - - acquireRawConnection() { - return Promise.resolve({ - driver: this.driver, - job: null, - }); - } - - // validateConnection(connection) { - // return ( - // connection && - // !connection._fatalError && - // !connection._protocolError && - // !connection._closing && - // !connection.stream.destroyed - // ); - // } - - destroyRawConnection(connection) { - return this.cancelJob(connection); - } - - wrapIdentifier(value) { - return value !== '*' ? `\`${value}\`` : '*'; - } - - cancelJob(connection) { - if (connection.job === null) { - return Promise.resolve(); - } - const cancelJobRequest = connection.job.cancel(); - connection.job = null; - return cancelJobRequest; - } - - _query(connection, obj) { - const queryConfig = { - ...obj.options, - query: obj.sql, - params: obj.bindings, - }; - - return this.createJob(connection, queryConfig) - .then(connection => this.getJobResults(connection, obj)) - .catch(err => { - this.cancelJob(connection); - throw err; - }); - } - - createJob(connection, queryConfig) { - return Promise.resolve( - connection.driver.createQueryJob(queryConfig).then(res => { - connection.job = res[0]; - return connection; - }), - ); - } - - getJobResults(connection, obj) { - return connection.job.getQueryResults({ autoPaginate: false }).then(res => { - obj.response = res[0]; - connection.job = null; - return obj; - }); - } -} +// // import Client from "knex/lib/client"; +// +// import { Knex, knex } from 'knex'; +// import { Database } from 'ibm_db'; +// import Client = knex.Client; +// +// export class IbmDbClient extends Client { +// constructor(config) { +// super(config); +// this.dialect = 'ibm_db'; +// this.driverName = 'ibm_db'; +// this.canCancelQuery = true; +// } +// +// _driver() { +// return new Database(); +// } +// +// acquireRawConnection() { +// return Promise.resolve({ +// driver: this.driver, +// job: null, +// }); +// } +// +// // validateConnection(connection) { +// // return ( +// // connection && +// // !connection._fatalError && +// // !connection._protocolError && +// // !connection._closing && +// // !connection.stream.destroyed +// // ); +// // } +// +// destroyRawConnection(connection) { +// return this.cancelJob(connection); +// } +// +// wrapIdentifier(value) { +// return value !== '*' ? `\`${value}\`` : '*'; +// } +// +// cancelJob(connection) { +// if (connection.job === null) { +// return Promise.resolve(); +// } +// const cancelJobRequest = connection.job.cancel(); +// connection.job = null; +// return cancelJobRequest; +// } +// +// _query(connection, obj) { +// const queryConfig = { +// ...obj.options, +// query: obj.sql, +// params: obj.bindings, +// }; +// +// return this.createJob(connection, queryConfig) +// .then(connection => this.getJobResults(connection, obj)) +// .catch(err => { +// this.cancelJob(connection); +// throw err; +// }); +// } +// +// createJob(connection, queryConfig) { +// return Promise.resolve( +// connection.driver.createQueryJob(queryConfig).then(res => { +// connection.job = res[0]; +// return connection; +// }), +// ); +// } +// +// getJobResults(connection, obj) { +// return connection.job.getQueryResults({ autoPaginate: false }).then(res => { +// obj.response = res[0]; +// connection.job = null; +// return obj; +// }); +// } +// }