javascript - 使用多边形列对批量插入错误进行续集
问题描述
我有以下模型,其中有一列多边形
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('p_zones', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
points: {
type: Sequelize.GEOMETRY('POLYGON')
},
});
},
down: async (queryInterface) => {
await queryInterface.dropTable('ZonePoints');
}
};
当我尝试使用带有命令的 sequelize-cli 播种时npx sequelize-cli db:seed:all
const polygon = {
type: 'Polygon',
coordinates: [
[
[10, 10],
[20, 10],
[20, 20],
[10, 20],
[10, 10],
],
],
};
const data = [{ points: polygon }];
await queryInterface.bulkInsert('p_zones', data);
我收到以下错误:
ERROR: Invalid value {
type: 'Polygon',
coordinates: [ [ [ 10, 10 ], [ 20, 10 ], [ 20, 20 ], [ 10, 20 ], [ 10, 10 ] ] ]
}
我究竟做错了什么?
解决方案
对于版本 6 ,这似乎是github 上的一个未解决问题Sequelize
。您可以尝试Americas
建议的内容GitHub
,即
await queryInterface.bulkInsert(
'p_zones',
data,
{},
{ points: { type: Sequelize.GEOMETRY('POLYGON') } });
postgres
虽然我必须承认,当我对数据库执行上述操作时,出现以下错误:
Executing (default): INSERT INTO "p_zones" ("points") VALUES (GeomFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))'));
(node:18964) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: function geomfromtext(unknown) does not exist
at Query.formatError ...
但希望这只是一个错误,PostGIS
因为我拥有的特定版本。
顺便说一句,如果它是一个.bulkCreate
语句而不是一个语句,则您的插入可以正常工作.bulkInsert
。.bulkInsert
不幸的是,如果不先定义整个模型,我不知道如何执行 a 。你可以尝试的事情:
- 构造一个原始查询并以这种方式进行批量插入。
- 尝试通过
sequelize
从 访问对象来定义模型queryInterface.sequelize
,然后执行 a.bulkCreate
,这不会给您任何错误。
推荐阅读
- java - Spring MVC - 尽管用户名和密码正确,但仍将我重定向到我的登录失败映射
- php - 由于连字符,pq_query 语法错误。我怎么写这个?
- sparql - 在参与者的 wikidata 查询中应用 group_concat
- visual-studio - 为什么oscdimg.exe,在Visual Studio下,不能识别为内部或外部命令、可运行程序或批处理文件
- filter - 如何根据另一个过滤器中的选择来控制过滤器的值
- python - 如何访问张量中的特定值?
- python - 在 sklearn 中处理具有多个值的分类数据
- coldfusion - 在 ColdFusion 中导出到 Excel
- ruby - 堆栈级别太深。功能
- java - 将矩阵划分为四个子块