set-isolation-level-query.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { IsolationLevel } from '@sequelize/core';
  2. import { expectsql, sequelize } from '../../support';
  3. const dialect = sequelize.dialect;
  4. const notSupportedError = new Error(`Isolation levels are not supported by ${dialect.name}.`);
  5. const queryNotSupportedError = new Error(
  6. `setIsolationLevelQuery is not supported by the ${dialect.name} dialect.`,
  7. );
  8. describe('QueryGenerator#setIsolationLevelQuery', () => {
  9. const queryGenerator = sequelize.queryGenerator;
  10. it('should generate a query for setting the isolation level to READ COMMITTED', () => {
  11. expectsql(() => queryGenerator.setIsolationLevelQuery(IsolationLevel.READ_COMMITTED), {
  12. default: 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
  13. sqlite3: new Error(
  14. `The ${IsolationLevel.READ_COMMITTED} isolation level is not supported by ${dialect.name}.`,
  15. ),
  16. snowflake: notSupportedError,
  17. 'db2 ibmi mssql': queryNotSupportedError,
  18. });
  19. });
  20. it('should generate a query for setting the isolation level to READ UNCOMMITTED', () => {
  21. expectsql(() => queryGenerator.setIsolationLevelQuery(IsolationLevel.READ_UNCOMMITTED), {
  22. default: 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
  23. sqlite3: 'PRAGMA read_uncommitted = 1',
  24. snowflake: notSupportedError,
  25. 'db2 ibmi mssql': queryNotSupportedError,
  26. });
  27. });
  28. it('should generate a query for setting the isolation level to REPEATABLE READ', () => {
  29. expectsql(() => queryGenerator.setIsolationLevelQuery(IsolationLevel.REPEATABLE_READ), {
  30. default: 'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ',
  31. sqlite3: new Error(
  32. `The ${IsolationLevel.REPEATABLE_READ} isolation level is not supported by ${dialect.name}.`,
  33. ),
  34. snowflake: notSupportedError,
  35. 'db2 ibmi mssql': queryNotSupportedError,
  36. });
  37. });
  38. it('should generate a query for setting the isolation level to SERIALIZABLE', () => {
  39. expectsql(() => queryGenerator.setIsolationLevelQuery(IsolationLevel.SERIALIZABLE), {
  40. default: 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
  41. sqlite3: 'PRAGMA read_uncommitted = 0',
  42. snowflake: notSupportedError,
  43. 'db2 ibmi mssql': queryNotSupportedError,
  44. });
  45. });
  46. });