如何附加nodejs序列化json字段的模型列表

编程入门 行业动态 更新时间:2024-10-10 15:18:14

如何附加nodejs序列化json<a href=https://www.elefans.com/category/jswz/34/1771443.html style=字段的模型列表"/>

如何附加nodejs序列化json字段的模型列表

如何附加在nodejs Sequelize中提交的JSON列表

数据库:Postgres

我有一个这样的模型字段:

student_list:
    {
        type: Sequelize.ARRAY(Sequelize.JSON),
        allowNull: true
    },

我正在尝试以这种方式附加JSON的Sequelize数组,但未成功附加列表:

var data =  ({'share_by':"aaa",'list_name':"list_name"})
student.update( 
                {'student_list': Sequelize.fn('array_append', Sequelize.col('student_list'), data)},
                {'where': {studet_id: student_id}}
                );

如何执行此操作?

回答如下:您可以执行find()并获取元素值,更新元素并使用已更新的数据进行更新。像这样:

// Get the actual student data const student = await student.findOne(studentId); // Spread and add the new value const student_list = { ...student_list, data }; // Update the field await student.update( { student_list }, { where: { student_id } } );

更多推荐

如何附加nodejs序列化json字段的模型列表

本文发布于:2024-05-07 12:24:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   模型   序列化   列表   nodejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!