IT/코딩 관련 팁

cubrid(큐브리드)

KeepGooing 2021. 5. 25. 16:56
반응형
app.js

const dbConCubrid = async() =>{

    const config = {
        host :'localhost',
        port :30000,
        user :'dba',
        password :'-',
        database :'chatbot'
    }

    global.cubridDBCon = CUBRID.createCUBRIDConnection(config);
    
    cubridDBCon.connect((err) =>{
    if(err) {
        console.log(err)
    }
    else{
        cubridDBCon.close((e)=>{if(e) console.log(e); else console.log('connection is closed');})
    } 
})

}

dbConCubrid();

---------------------------------------------------------------------------------------------
dialog.dialog.js

const appRoot                = require('app-root-path');
const cubrid                 = ('/src/common/cubrid');
const query                  = require(`${appRoot}${cubrid}/dialog/query`);


const dialog = {

        async test(totalInfo) {
          console.log('totalInfo' , totalInfo);
          const rows = await cubridDBCon.queryAllAsObjects(query.sql);
          return rows
            
        }

}
module.exports = dialog
---------------------------------------------------------------------------------------------

const query = {
    sql : `SELECT
    *
    FROM
    intent_service
    WHERE
    lib_name='test'`
}


module.exports = query



---------------------------------------------------------------------------------------------

const appRoot                   = require('app-root-path');
const cubrid                    = ('/src/common/cubrid');
const dialog                    = require(`${appRoot}${cubrid}/dialog/dialog`);


const Cubrid = {
    test : dialog.test
}

module.exports = Cubrid;



 

 

 

app.js 

 

 

 

웹 실행시

큐브리드 DB 접속

후에 CLIENT 함수선언을 글로벌로 하여

다른 파일에서도 간편히 사용하도록 설계

 

 

작업 중 발생한 문제

 

 

1.

const Cubrid = {

    test dialog.test

}

 

문구에서 

const Cubrid = {

    test dialog.test()

}

로 프로퍼티에 test() 같은 함수 형태로 넣을 시 

global형태의 큐브리드 클라이언트의 값 undefined됨

이는 새로운 Object 형태의 값을 상위 객체로 갖는 것인 것으로 파악됨

 

 

따라서 프로퍼티 형태를 준수하여 코드를 짜도록 주의

 

 

2.

비동기 형태의 함수호출 주의할 것

async await나 promise 형태에 맞춰 값을 return 하지 않는 경우

또 위 두형태의 return 값을 전달 방식이 다름을 인식

 

-promise는 then 과 resolve를 통해

-async await는 직접적으로 return 값을 변수에 담을 수 있다.

 

 

 

반응형