2016-06-13 5 views
1

나는 배열 내가 objection.js를 사용하여 MySQL 데이터베이스에 newData을 삽입하고 싶어일괄 삽입

newData = [{ sId: 'XXXXXX', itemlName: 'LSストレッ', iCode: 'XXXXXX', iType: '', skus: 'XXXXXXX', iLevel: 'L2', cCode: '88', cName: 'Other', sCode: '999', sName: 'No Control', pLengthCode: '988', core: 'N', sCode: '1', dCode: 'XX', gDeptCode: 'XX', gDeptName: 'Women\\\'s Items', rCode: 'jqs' },{ sId: 'XXXXXX', itemlName: 'LSストレッ', iCode: 'XXXXXX', iType: '', skus: 'XXXXXXX', iLevel: 'L2', cCode: '88', cName: 'Other', sCode: '999', sName: 'No Control', pLengthCode: '988', core: 'N', sCode: '1', dCode: 'XX', gDeptCode: 'XX', gDeptName: 'Women\\\'s Items', rCode: 'jqs' }] 

있습니다.

samplemodel.query().insert(newData); 

어떻게 이의를 사용하여 MySQL의 데이터베이스에 배열 데이터의 일괄 삽입을 수행 할 수 있습니다 -

Error: batch insert only works with Postgresql

내 삽입 코드는 : 내 노드 응용 프로그램을 실행할 때, 나는 오류가 말하고있어 .js?

답변

1

오류 : 일괄 삽입은 당신이 그것을 작동하게하는 대신 MySQL의의 포스트 그레스의 필요하다는 것을 의미한다, PostgreSQL을

잘 작동합니다.

EDIT1 : 워드 프로세서

는 :

If you are using Postgres the inserts are done in batches for maximum performance. On other databases the rows need to be inserted one at a time. This is because postgresql is the only database engine that returns the identifiers of all inserted rows and not just the first or the last one.

당신이 MySQL을 사용하는 경우에는 "newData의"배열의 각 요소에 대해

samplemodel.query().insert(data); 

을해야한다는 것을 의미한다.

1

당신은 필요한 경우 여러 쿼리를 사용하여 모든 데이터베이스와 함께 작동

samplemodel.query().insertWithRelated(newData);

를 호출 할 수 있습니다.