bulk-insert-query.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { DataTypes, literal } from '@sequelize/core';
  2. import { beforeAll2, expectsql, sequelize } from '../../support';
  3. describe('QueryGenerator#bulkInsertQuery', () => {
  4. const queryGenerator = sequelize.queryGenerator;
  5. const vars = beforeAll2(() => {
  6. const User = sequelize.define(
  7. 'User',
  8. {
  9. firstName: DataTypes.STRING,
  10. },
  11. { timestamps: false },
  12. );
  13. return { User };
  14. });
  15. it('parses named replacements in literals', async () => {
  16. const { User } = vars;
  17. const sql = queryGenerator.bulkInsertQuery(
  18. User.table,
  19. [
  20. {
  21. firstName: literal(':injection'),
  22. },
  23. ],
  24. {
  25. replacements: {
  26. injection: 'a string',
  27. },
  28. },
  29. );
  30. expectsql(sql, {
  31. default: `INSERT INTO [Users] ([firstName]) VALUES ('a string');`,
  32. mssql: `INSERT INTO [Users] ([firstName]) VALUES (N'a string');`,
  33. // TODO: ibmi should be the same as `default`, since the 'returning' option is not specified
  34. ibmi: `SELECT * FROM FINAL TABLE (INSERT INTO "Users" ("firstName") VALUES ('a string'))`,
  35. });
  36. });
  37. });