Guest User

Untitled

a guest
Jan 9th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /**
  2. * GET /api/test
  3. * Test API example.
  4. */
  5. export let getTest = (req: Request, res: Response, next: NextFunction) => {
  6. // const token = req.user.tokens.find((token: any) => token.kind === "facebook");
  7. const db = new Database();
  8.  
  9. db.getConnection()
  10. .then(con => {
  11. con.execute('SELECT * FROM BTO_MDS.AlARMS', {}, { maxRows: 22000 })
  12. .then(result => {
  13. con.release();
  14. res.json({data: result.rows});
  15. })
  16. .catch(ex => {
  17. con.release();
  18. res.status(500).json({message: ex.message});
  19. });
  20. })
  21. .catch(ex => {
  22. res.status(500).json({message: ex.message});
  23. });
  24.  
  25. };
  26.  
  27. import * as oracledb from 'oracledb';
  28. import { IConnectionPool } from 'oracledb';
  29.  
  30. const config = {
  31. user: 'user',
  32. password: 'pw',
  33. connectString: 'databaseNameFromTNSNames',
  34. poolMax: 16
  35. };
  36.  
  37. export default class Database {
  38. private pool: IConnectionPool;
  39. constructor() {
  40. }
  41.  
  42. public createPool(): void {
  43. oracledb.createPool(config).then(conpool => {
  44. this.pool = conpool;
  45. console.log('Connection Pool created!');
  46. },
  47. err => {
  48. console.log('Error creating pool!');
  49. });
  50. }
  51.  
  52. public getConnection() {
  53. return oracledb.getConnection();
  54. }
  55. }
Add Comment
Please, Sign In to add comment