Guest User

Untitled

a guest
Jan 16th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. const MariaDB = require('mariadb');
  2. const dbConfig = require('../config').db;
  3.  
  4. const MariaDBConnectionPool = MariaDB.createPool({
  5. user: dbConfig.user,
  6. password: dbConfig.password,
  7. host: dbConfig.dburl,
  8. database: dbConfig.database,
  9. connectionLimit: 10
  10. });
  11.  
  12. const query = '<쿼리문>';
  13. const params = [<파라미터1>, <파라미터2>, ...];
  14.  
  15. const promise = new Promise((resolve, reject)=> {
  16. let DBconn;
  17. MariaDBConnectionPool.getConnection()
  18. .then((conn) => {
  19. DBconn = conn;
  20. return DBconn.query(query, params)
  21. }).then(result => {
  22. DBconn.end();
  23. return resolve(result)
  24. }).catch(e => {
  25. DBconn.end();
  26. reject(e);
  27. })
  28. })
  29.  
  30. promise.then( result => {
  31. //result에 쿼리에 대한 결과가 담긴다.
  32. }).catch(e => {
  33. //에러 처리
  34. })
Add Comment
Please, Sign In to add comment