Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. pool = new pg.Pool({
  2. user: 'devuser',
  3. database: 'ecommerce_api_dev',
  4. password: '',
  5. port: 5432,
  6. max: 10,
  7. idleTimeoutMillis: 30000
  8. });
  9.  
  10.  
  11. /*
  12. Create a store
  13.  
  14. */
  15. createStore: function (req, res) {
  16. var dbname = 'store_' + generateID(1000000,9999999);
  17. var q_CreateStoreInfo = 'CREATE TABLE "public"."store_info" (' +
  18. '"id" serial,' +
  19. '"title" text,' +
  20. '"address" text,' +
  21. '"created_on" TIMESTAMP WITH TIME ZONE DEFAULT 'now()',' +
  22. '"inactive_on" TIMESTAMP WITH TIME ZONE DEFAULT null,' +
  23. '"active" boolean,' +
  24. '"subscription_type" text,' +
  25. 'PRIMARY KEY ("id")' +
  26. ');';
  27. pool.connect(function(err, client, done) {
  28. if (err) {
  29. return console.error('error fetching client from pool', err);
  30. }
  31.  
  32. client.query('CREATE DATABASE ' + dbname, null, function(err, result) {
  33. if(err) {
  34. return console.error('[QUERY ERROR]', err);
  35. }
  36.  
  37. console.log('[QUERY SUCCESS]', result);
  38. });
  39.  
  40. client.query(q_CreateStoreInfo, null, function(err, result) {
  41. if(err) {
  42. return console.error('[QUERY ERROR]', err);
  43. }
  44.  
  45. console.log('[QUERY SUCCESS]', result);
  46. });
  47. });
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement