sqlite-master.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. const chai = require('chai');
  3. const expect = chai.expect;
  4. const Support = require('../../support');
  5. const dialect = Support.getTestDialect();
  6. const { DataTypes } = require('@sequelize/core');
  7. if (dialect === 'sqlite3') {
  8. describe('[SQLITE Specific] sqlite_master raw queries', () => {
  9. beforeEach(async function () {
  10. this.sequelize.define(
  11. 'SomeTable',
  12. {
  13. someColumn: DataTypes.INTEGER,
  14. },
  15. {
  16. freezeTableName: true,
  17. timestamps: false,
  18. },
  19. );
  20. await this.sequelize.sync({ force: true });
  21. });
  22. it('should be able to select with tbl_name filter', async function () {
  23. const result = await this.sequelize.query(
  24. "SELECT * FROM sqlite_master WHERE tbl_name='SomeTable'",
  25. );
  26. const rows = result[0];
  27. expect(rows).to.have.length(1);
  28. const row = rows[0];
  29. expect(row).to.have.property('type', 'table');
  30. expect(row).to.have.property('name', 'SomeTable');
  31. expect(row).to.have.property('tbl_name', 'SomeTable');
  32. expect(row).to.have.property('sql');
  33. });
  34. it('should be able to select *', async function () {
  35. const result = await this.sequelize.query('SELECT * FROM sqlite_master');
  36. const rows = result[0];
  37. expect(rows).to.have.length(2);
  38. for (const row of rows) {
  39. expect(row).to.have.property('type');
  40. expect(row).to.have.property('name');
  41. expect(row).to.have.property('tbl_name');
  42. expect(row).to.have.property('rootpage');
  43. expect(row).to.have.property('sql');
  44. }
  45. });
  46. it('should be able to select just "sql" column and get rows back', async function () {
  47. const result = await this.sequelize.query(
  48. "SELECT sql FROM sqlite_master WHERE tbl_name='SomeTable'",
  49. );
  50. const rows = result[0];
  51. expect(rows).to.have.length(1);
  52. const row = rows[0];
  53. expect(row).to.have.property(
  54. 'sql',
  55. 'CREATE TABLE `SomeTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `someColumn` INTEGER)',
  56. );
  57. });
  58. });
  59. }