我無法插入文本當文本中包含字符串我的數據庫中的文本「$(...)」 作爲我的代碼返回錯誤:屬性「...」不存在。
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);
有沒有某種「這只是文本」屬性我錯過了?
感謝
EDIT使用$()時,語法等變量添加到整個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.
請更確切地說明哪一行/操作無法正確執行。還請提供生成的查詢和完整的代碼(您的示例中的代碼無法工作,因爲您在生成查詢時未指定任何表)。 –