'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.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | chinzano |