我无法插入文本当文本中包含字符串我的数据库中的文本“$(...)” 作为我的代码返回错误:属性“...”不存在。
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.
请更确切地说明哪一行/操作无法正确执行。还请提供生成的查询和完整的代码(您的示例中的代码无法工作,因为您在生成查询时未指定任何表)。 –