Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import * as Mysql from "mysql";
  2. import { Localconfig } from "../environment/localconfig";
  3.  
  4. export class Database {
  5. private static pool = Mysql.createPool({
  6. connectionLimit: 20,
  7. host: Localconfig.mysql.host,
  8. user: Localconfig.mysql.user,
  9. password: Localconfig.mysql.password,
  10. database: Localconfig.mysql.database
  11. });
  12.  
  13. public static exec(query: string, params: any[], callback: Function) {
  14. return this.pool.getConnection((err, connection) => {
  15. if (err) {
  16. if (connection) connection.release();
  17. throw err;
  18. }
  19. connection.query(query, params, (err, res) => {
  20. connection.release();
  21. if (!err) {
  22. callback(res);
  23. }
  24. });
  25. connection.on("error", err => {
  26. throw err;
  27. });
  28. });
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement