Sequelize 7 alpha 29: mapping of (?) placeholder has changed #16821
-
Code that works on Sequelize 6 broke with Sequelize 7 (alpha 29). The database is Postgres (15 I believe). I must admit I do not understand deeply how replacing questionmark placeholders work. But long time ago I got it to work via trial and error and it's quite problematic now that it doesn't any more, especially because I am forced to use the new version of Sequelize because only it has support for connecting to Google Cloud SQL. This is the code that used to work (and still works with 6): const values = (?)
const sql = `
INSERT INTO mytable (created_at,num_block,num_found)
VALUES ${values}
`
const data = // .... we prepare some data
console.log('Data:', data)
return db.query(sql, {
replacements: data,
type: db.QueryTypes.INSERT
})
} This is the console log of data (a timestamp and two strings):
This is the error with Sequelize 7:
At the moment data is mapped onto the ? placeholder something is happening with types that didn't happen before. Struggling to figure out what, any help appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! I think you can do the following as well: const query = `
INSERT INTO mytable (created_at,num_block,num_found)
VALUES ?
`;
const data = [
sql.list([new Date(), '12896912', '0'])
];
return db.query(query, {
replacements: data,
type: db.QueryTypes.INSERT
}) |
Beta Was this translation helpful? Give feedback.
Hi!
The serialization of values changed between v6 and v7, if you need an SQL list instead of an SQL array, you need to use this: https://sequelize.org/docs/v7/querying/raw-queries/#sqllist
I think you can do the following as well: