이것은 아마도 어리석은 질문 일 뿐이지 만 노드와 postgresql에 익숙하지 않으므로 고심하고 있습니다.일치하는 열 이름이없는 개체 삽입
나는 울부 짖는 소리의 예로서, 데이터베이스에 여러 개체를 삽입 할 pgp.helpers.insert
를 사용하는 것을 시도하고있다 :
users = [{mycolumn:{name: 'John', age:23}}, {mycolumn:{name: 'Mike', age: 30}}];
query = pgp.helpers.insert(users, ['mycolumn:json'], 'mytable');
// insert into "mytable"("mycolumn") values('{"name":"John","age":23}'),('{"name":"Mike","age":30}')
삽입 위의 코드를 mytable
2 행에 jsonb로 mycolumn
와 함께.
하지만 같은, 내 원래의 객체를 포장하지 않고, 객체의 배열 내부에 직선으로 mycolumn
값을 삽입하려고 : 개체가 '아무튼 이후, 물론
users = [{name: 'John', age:23}, {name: 'Mike', age: 30}];
query = pgp.helpers.insert(users, ['mycolumn:json'], 'mytable');
// Error: Property 'mycolumn' doesn't exist.
가 작동하지 않습니다 t mycolumn
속성을 포함합니다. 하지만 난 내 배열에서 열 이름으로 원래 개체를 래핑, 특히 내가 행 수백만 (물론 일괄 작업)와 함께 일하고 있기 때문에 반복되지 우아하다고 생각합니다.
미리 감사드립니다. 사용 후
{
name: 'mycolumn',
init: c => c.source // use the source object itself
}
즉
const cs = new pgp.helpers.ColumnSet([
{
name: 'mycolumn',
init: c => c.source
}
], {table: 'mytable'});
과 :
는