Guest User

Untitled

a guest
Nov 8th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. const ODatabase = require('orientjs').ODatabase;
  2. const genericPool = require('generic-pool');
  3.  
  4.  
  5. const factory = {
  6. create: function(){
  7. const db = new ODatabase({
  8. host: 'localhost',
  9. port: 2424,
  10. username: 'admin',
  11. password: 'admin',
  12. name: 'GratefulDeadConcerts'
  13. });
  14. return db.open();
  15. },
  16.  
  17. destroy: function(client){
  18. return client.close();
  19. }
  20. }
  21.  
  22. const opts = {
  23. max: 10, // maximum size of the pool
  24. min: 2 // minimum size of the pool
  25. }
  26.  
  27. let pool = genericPool.createPool(factory, opts)
  28.  
  29. pool.acquire()
  30. .then(function(db){
  31. db.query('select from v limit 1')
  32. .then(function(res){
  33. console.log(res);
  34. return pool.release(db);
  35. })
  36. .then(function(){
  37. return pool.drain();
  38. })
  39. .then(function(){
  40. return pool.clear();
  41. })
  42. })
Add Comment
Please, Sign In to add comment