Reputation: 131
I looked for this question everywhere but, I haven't found it. I'm using Sequelize for Postgres, and I'm trying to add content to a model. It's not throwing any errors, except just a warning that says that string based operations have been deprecated, but this isn't an operation.
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
Here's my model and .create code
const Sequelize = require('sequelize');
const sequelizeInstance = new Sequelize('journal_entries', 'KupidoExportLLC',
{
dialect: 'postgres'
});
module.exports = function(sequelizeInstance, DataTypes){
const Entries = sequelizeInstance.define('entries', {
user: Sequelize.STRING,
title: Sequelize.STRING,
content: Sequelize.TEXT
})
Entries.sync().then(function(){
Entries.create({
user: 'I need to get this to work',
title: 'Ill be really happy when this does work',
content: 'It will work this time'
})
});
return Entries;
}
Here's what my commandline is showing
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:242:13
When I go look at my table, it's empty
journal_entries=# SELECT * FROM entries;
id | user | title | content | createdAt | updatedAt
----+------+-------+---------+-----------+-----------
(0 rows)
I have no idea what else it could be
Upvotes: 0
Views: 4274
Reputation: 651
you are working with Promises here, you have either to await or return them. if you have async await available in your node version you could just do:
module.exports = async function(sequelizeInstance, DataTypes){
const Entries = sequelizeInstance.define('entries', {
user: Sequelize.STRING,
title: Sequelize.STRING,
content: Sequelize.TEXT
});
await sequelizeInstance.sync();
await Entries.create({
user: 'I need to get this to work',
title: 'Ill be really happy when this does work',
content: 'It will work this time'
});
const entries = await Entries.findAll();
console.log(entries.map(e => e.get({ plain: true })));
return Entries;
};
or if not
module.exports = async function(sequelizeInstance, DataTypes){
const Entries = sequelizeInstance.define('entries', {
user: Sequelize.STRING,
title: Sequelize.STRING,
content: Sequelize.TEXT
});
return sequelizeInstance.sync().then(() => {
return Entries.create({
user: 'I need to get this to work',
title: 'Ill be really happy when this does work',
content: 'It will work this time'
});
})
.then(() => {
return Entries.findAll().then(entries => {
console.log(entries.map(e => e.get({ plain: true })));
return entries;
})
});
};
Upvotes: 1
Reputation: 2028
You need to turn off the warnings.
In your config.JSON file or (If you have initialize the connection in the same file) Turn the warning off, as given:
IN Config.JSON
{
"development": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
},
"test": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
},
"production": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
}
}
Inline declaration of connection
const sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, dialect: config.dialect, pool: { max: 5, min: 0, idle: 10000 }, logging: false, freezeTableName: true, operatorsAliases: false });
Upvotes: 3