简体   繁体   中英

Sequelize ARRAY Datatype for PostgreSQL

I'm trying to use the ARRAY datatype for Sequelize (Node.js SQL ORM) with PostgreSQL. However I'm not exactly sure how to utilize it. I know how to set it on the schema but how do you push new items onto the array with a write and retrieve a specific index from the array in a query, etc.

I tried going to the docs to figure this out however theres not much documentation on this as opposed to other datatypes.

const { DataTypes } = require('sequelize');

const Data = sequlize.define('data', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  title: { type: DataTypes.STRING },
  imgs: { type: DataTypes.ARRAY(DataTypes.STRING) },
  wikiLink: { type: DataTypes.STRING },
  mapsLink: { type: DataTypes.ARRAY(DataTypes.STRING) },
  authorInfo: { type: DataTypes.ARRAY(DataTypes.STRING) }
});

honestly, i don't know, how much this is correct, but that works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM