sequelize-auto
sequelize-auto copied to clipboard
defaultValue for JSON(B) properties includes ", causing error
In Postgres, create a table with json default value
CREATE TABLE test(
id text not null,
props jsonb DEFAULT '{"optionA": 14, "optionB": "half"}'
);
Generated model is
import _sequelize from 'sequelize';
const { Model, Sequelize } = _sequelize;
export default class test extends Model {
static init(sequelize, DataTypes) {
return super.init({
id: {
type: DataTypes.TEXT,
allowNull: false,
primaryKey: true
},
props: {
type: DataTypes.JSONB,
allowNull: true,
defaultValue: {\"optionA\": 14, \"optionB\": \"half\"}
}
}, {
sequelize,
tableName: 'test',
schema: 'public',
timestamps: false
});
}
}
causing node error
SyntaxError: Invalid or unexpected token
at Loader.moduleStrategy (node:internal/modules/esm/translators:146:18)
"version": "0.8.8"
Thanks
PS: the default value is already set in db. It would make sense to leave out that JSONB column on insert, if not specifically set in .create(). Changing default column values in db shouldn't require updating models.
Just tested deleting defaultValue and everything works great. The best solution for this issue would be #592