daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Dec 13th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client } = require('pg');
  2. const connectionString = 'postgresql://postgres:postgres@localhost:5432/platform-test';
  3.  
  4. const client = new Client({
  5.     connectionString: connectionString,
  6. });
  7.  
  8. let brands = {"sEcho":0,"iTotalRecords":6,"iTotalDisplayRecords":6,"aaData":[{"marca_id":"1","marca_nome":"LG","marca_cadastro":"25\/07\/2014 17:31:39","marca_check":"<input type='checkbox' value='1' name='cb_marca_del' id='cb_marca_del' \/>"},{"marca_id":"2","marca_nome":"SAMSUNG","marca_cadastro":"25\/07\/2014 17:31:47","marca_check":"<input type='checkbox' value='2' name='cb_marca_del' id='cb_marca_del' \/>"},{"marca_id":"3","marca_nome":"MOTOROLA","marca_cadastro":"25\/07\/2014 17:31:53","marca_check":"<input type='checkbox' value='3' name='cb_marca_del' id='cb_marca_del' \/>"},{"marca_id":"4","marca_nome":"APPLE","marca_cadastro":"25\/07\/2014 17:32:00","marca_check":"<input type='checkbox' value='4' name='cb_marca_del' id='cb_marca_del' \/>"},{"marca_id":"5","marca_nome":"NOKIA","marca_cadastro":"25\/07\/2014 17:32:05","marca_check":"<input type='checkbox' value='5' name='cb_marca_del' id='cb_marca_del' \/>"},{"marca_id":"6","marca_nome":"HUAWEI","marca_cadastro":"03\/11\/2014 12:00:59","marca_check":"<input type='checkbox' value='6' name='cb_marca_del' id='cb_marca_del' \/>"}]};
  9. brands = brands.aaData.map( e => e.marca_nome );
  10.  
  11. client.connect();
  12.  
  13. brands.forEach(brand => {
  14.     console.log(brand);
  15.     client.query("INSERT INTO brands (created_at, updated_at, name) VALUES (now(), now(), '"+ brand +"')");
  16. });
RAW Paste Data
Top