dynamic import path with arguments

sangwoo noh·2022년 7월 25일
0

prisma

목록 보기
2/2
/* 
// client.ts
export * from './testClient'
export * from './test111Client'
export * from './videohelpClient'
export * from './videohelp_gs_210504_A001Client'
export * from './videohelp_kl_190509_A001Client'
export * from './videohelp_kp_200902_A001Client'
export * from './videohelp_sb_210702_A001Client'
export * from './videohelp_tc02_210511_A001Client'
export * from './videohelp_tc_200210_A001Client'
export * from './videohelp_ts01_200610_A001Client'
export * from './videohelp_ts02_200610_A002Client'
export * from './videohelp_ts03_200610_A003Client'
// testClient.ts
import { PrismaClient } from '@pm/clientModules/testClient'

export const testClient = new PrismaClient()

export default testClient
// main.ts
import * client from ".@client/client"   

const c_dbname = ["db1", "db2", "db3"]


   const dbINDEX = c_dbname.indexOf(dbname)
    if (c_dbname.includes(dbname)) {
      const getUser =
        await client?.[dbINDEX].tUSER.findFirst({
          where: {
            OR: [
              { AND: [{ EMAIL: email }, { DELFLAG: '0' }] },
              { AND: [{ USERID: userid }, { DELFLAG: '0' }] },
            ],
          },
          orderBy: [
            {
              CDATETIME: 'desc',
            },
          ],
          select: {
            USERNAME: true,
            EMAIL: true,
            TELNO: true,
          },
        })
      console.log('getUser in prisma1111: ', getUser)
    } */
    
    
// 근데 이렇게하면 prisma client가 모여있는곳에서 트리쉐이킹 문제가 해결이 안되기때문에 
엄청 느려짐....
// or 이 패턴을 연구해보면 될듯..
 await import(`@client/videohelp_kl_190509_A001Client`).then(
        async client => {
          const getUser = await client.default.tUSER.findFirst({
            where: {
              OR: [
                { AND: [{ EMAIL: email }, { DELFLAG: '0' }] },
                { AND: [{ USERID: userid }, { DELFLAG: '0' }] },
              ],
            },
            orderBy: [
              {
                CDATETIME: 'desc',
              },
            ],
            select: {
              USERNAME: true,
              EMAIL: true,
              TELNO: true,
            },
          })
          console.log('getUser in prisma: ', getUser)
        },
      )
profile
하기로 했으면 하자

0개의 댓글