Nodejs: postgresql 무 작위 로 10 만 개의 데이터 테스트 삽입
model : 42
model name : Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
시스템 정보: Linux sec 3.5.0 - 45 - generic \ # 68 ~ precise 1 - Ubuntu SMP 12 월 4 일 16: 18: 46 UTC 2013 x8664 x86_64 x86_64 GNU/Linux
node postgresql package:https://github.com/brianc/node-postgres
db / index. js 부분:
var pg = require('pg');
var conString = "postgres://test:test@localhost/pgs";
exports.pg_exec = function(prepared_obj,cb){
pg.connect(conString, function(err, client, done) {
if(err) {
cb(err,{"rowCount":0})
return;
}
client.query(prepared_obj, function(err, result) {
done();
cb(err,result);
});
});
}
index. js 부분
/**
* Created by ty4z2008 on 14-1-19.
*/
var pg_exec = require("./db").pg_exec;
(function(){
console.log('start pg_insert');
var rand_ship = new Array(' ','EMS',' ',' ',' ',' ','UPS',' ',' '),
rand_alp=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i',
'j','k','m','n','p','Q','r','s','t','u','v','w','x','y','z', '2','3','4','5',
'6','7','8','9'),
rand_number=new Array(1,2,3,4,5,6,7,8,9,0),
rand_add=new Array(' ',' ',' ',' ',' ',' '),
rand_gender=new Array(' ',' '),
rand_state=new Array(' ',' ',' ',' ',' ');
var rand_ship_length=rand_ship.length,
rand_alp_length=rand_alp.length,
rand_number_length=rand_number.length,
rand_add_length=rand_add.length,
rand_state_length=rand_state.length,
rand_gender_length=rand_gender.length;
for(var i = 0; i < 50000; i++) {
var n=Math.floor(Math.random()*rand_number_length),
a=Math.floor(Math.random()*rand_alp_length),
e=Math.floor(Math.random()*rand_add_length),
s=Math.floor(Math.random()*rand_ship_length),
st=Math.floor(Math.random()*rand_state_length),
g=Math.floor(Math.random()*rand_gender_length),
price=Math.floor(Math.random()*100);
total_price=i+rand_number[n]+i;
count=rand_number[n]+rand_number[n]+2;
czipcode = i+rand_number[n] + i;
gender=rand_gender[g];
shipping=rand_ship[s];
payment=rand_add[e];
consignee="consignee"+rand_alp[a]+i;
caddr=rand_alp[a]+'caddr'+i;
cphone='1'+i+rand_number[n];
cmessage="cmessage"+rand_alp[a]+i;
ostate=rand_state[st];
pg_exec({
name:"insert",
text:" INSERT INTO " +
"orderinfo(total_price,price,count, otime, shipping, payment," +
" consignee,gender, caddr, czipcode, cphone, cmessage, ostate)" +
"VALUES($1, $2,$3, current_timestamp(2), $4, $5, $6, $7,$8,$9,$10,$11,$12)",
values:[total_price,price,count, shipping, payment,
consignee,gender, caddr, czipcode, cphone, cmessage, ostate]},
function(err){
if(err){
console.log(err);
return;
}
});
};
})();
sql 부분:
CREATE TYPE sex_enum AS ENUM(' ', ' ');
-- Table: orderinfo
-- DROP TABLE orderinfo;
CREATE TABLE orderinfo
(
order_id serial NOT NULL,
user_id serial NOT NULL,
price character varying(10), --
count character varying(10), --
total_price numeric(9,2), --
otime timestamp without time zone, --
shipping character varying(20), --
payment character varying(20), --
consignee character varying(20), --
gender sex_enum, -- -gender
caddr character varying(100),
czipcode character varying(10), --
cphone character varying(12), --
cmessage character varying(100),
ostate character varying(20), --
CONSTRAINT orderinfo_pkey PRIMARY KEY (order_id),
CONSTRAINT orderinfo_user_id_fkey FOREIGN KEY (user_id)
REFERENCES users (user_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE orderinfo
OWNER TO z71;
COMMENT ON COLUMN orderinfo.price IS ' ';
COMMENT ON COLUMN orderinfo.count IS ' ';
COMMENT ON COLUMN orderinfo.total_price IS '
';
COMMENT ON COLUMN orderinfo.otime IS ' ';
COMMENT ON COLUMN orderinfo.shipping IS '
';
COMMENT ON COLUMN orderinfo.payment IS '
';
COMMENT ON COLUMN orderinfo.consignee IS '
';
COMMENT ON COLUMN orderinfo.gender IS ' -gender
';
COMMENT ON COLUMN orderinfo.czipcode IS ' ';
COMMENT ON COLUMN orderinfo.cphone IS ' ';
COMMENT ON COLUMN orderinfo.ostate IS ' ';
한 1 분 정도 걸 렸 어 요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.