텍스트에 "$ (...)"문자열이 포함되어있을 때 데이터베이스에 텍스트를 삽입하는 데 문제가 있습니다 내 코드가 Error : Property '...' 존재하지 않습니다.
const pgp = require('pg-promise')({ promiseLib: bluebird });
const db = pgp(process.env.DATABASE_URL);
let values = [{text: 'this is fine'}, {text: 'this fails $(...)'}];
let cs = new pgp.helpers.ColumnSet(['text']);
let query = pgp.helpers.insert(values, cs);
db.manyOrNone(query);
"이 텍스트는"속성 중 일부가 누락 되었습니까?
덕분에 전체 SQL 호출에 다른 변수를 추가 할() 구문 $를 사용하는 경우 오류 만 발생했다
편집
'use strict';
const bluebird = require('bluebird');
const pgp = require('pg-promise')({ promiseLib: bluebird });
const db = pgp('postgres://localhost/okeydokey-local');
db.any(
'CREATE TABLE text_table (' +
'text_column text ' +
')'
);
let values = [{ text_column: 'this is fine' }, { text_column: 'this fails $(test)' }];
let cs = new pgp.helpers.ColumnSet(['text_column'], {table: 'text_table'});
let query = pgp.helpers.insert(values, cs);
console.log(query);
db.manyOrNone(query +
'some more SQL dependent on $(somethingElse)',
{
somethingElse: 'someValue'
}
);
출력
insert into "text_table"("text_column") values('this is fine'),('this fails $(test)')
Unhandled rejection Error: Property 'test' doesn't exist.
정확히 어떤 라인/작업이 실패했는지 자세히 알려주십시오. 또한 생성 된 쿼리와 전체 코드 (예 : 쿼리를 생성 할 때 테이블을 지정하지 않으므로 예제의 코드는 작동하지 않습니다)를 제공하십시오. –